Magic Squares

시간 제한1초메모리 제한2048 MB

요약
N개의 정사각형 변의 길이를 음이 아닌 정수로 정해 길이의 합이 정확히 D가 되게 하면서 길이 제곱 곱하기 비용의 합을 최소화한다.
난이도

보통10점 중 6점

유형
그리디, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

You have NN magic squares (numbered from 11 to NN). For each magic square, you can set the length of its side to any non-negative integers. The cost of each magic square is proportional to its area; magic square ii has a cost of C_iC\_i per unit area. In other words, if the length of magic square ii is set to kk, then it will cost you k2⋅C_ik^2 \cdot C\_i.

You want to build a wall with a length of DD using these magic squares. You have to line up all your magic squares next to each other, and their total length has to be exactly DD. The base of each magic square must fully touch the floor, i.e. you are not allowed to rotate the magic squares.

Determine the minimum total cost to build the wall.

입력

This problem has multiple test cases. The first line consists of an integer TT (1≤T≤201 ≤ T ≤ 20), which represents the number of test cases.

Each test case consists of two lines. The first line consists of two integers NN DD (1≤N≤10,0001 ≤ N ≤ 10\\, 000; 1≤D≤1071 ≤ D ≤ 10^7). The second line consists of NN integers C_iC\_i (1≤C_i≤10,0001 ≤ C\_i ≤ 10\\, 000).

출력

For each test case, output an integer in a single line representing the minimum total cost to build the wall.

예제2

  1. 예제 1

    입력
    3
    3 5
    500 1000 100
    1 4
    30
    4 4
    30 30 30 30
    
    예상 출력
    2100
    480
    120
    
  2. 예제 2

    입력
    3
    10 20
    1 2 3 4 5 6 7 8 9 10
    10 100
    1 2 3 4 5 6 7 8 9 10
    1 10000000
    10000
    
    예상 출력
    140
    3419
    1000000000000000000