Logo
(追記) (追記ここまで)

33103번 - Magic Squares 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB199844.444%

문제

You have $N$ magic squares (numbered from 1ドル$ to $N$). 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 $i$ has a cost of $C_i$ per unit area. In other words, if the length of magic square $i$ is set to $k,ドル then it will cost you $k^2 \cdot C_i$.

You want to build a wall with a length of $D$ 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 $D$. 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 $T$ (1ドル ≤ T ≤ 20$), which represents the number of test cases.

Each test case consists of two lines. The first line consists of two integers $N$ $D$ (1ドル ≤ N ≤ 10,円 000$; 1ドル ≤ D ≤ 10^7$). The second line consists of $N$ integers $C_i$ (1ドル ≤ C_i ≤ 10,円 000$).

출력

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

제한

예제 입력 1

3
3 5
500 1000 100
1 4
30
4 4
30 30 30 30

예제 출력 1

2100
480
120

For the first test case, set the length of the side of magic square 1ドル,ドル 2ドル$ and 3ドル$ to 1ドル,ドル 0ドル,ドル and 4ドル,ドル respectively. The total cost to build the wall is 1ドル^2 \cdot 500 + 0^2 \cdot 1000 + 4^2 \cdot 100 = 2100,ドル which can be shown to be the minimum.

For the second test case, the only solution is to set the length of the side of magic square 1ドル$ to 4ドル$. The total cost to build the wall is 4ドル^2 \cdot 30 = 480$.

For the third test case, set the length of the side of all magic squares to 1ドル$. The total cost to build the wall is 120ドル,ドル which can be shown to be the minimum.

예제 입력 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

예제 출력 2

140
3419
1000000000000000000

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2023 K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /