CF1850E.Cardboard for Pictures

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mircea has nn pictures. The ii-th picture is a square with a side length of sis_i centimeters.

He mounted each picture on a square piece of cardboard so that each picture has a border of ww centimeters of cardboard on all sides. In total, he used cc square centimeters of cardboard. Given the picture sizes and the value cc, can you find the value of ww?

A picture of the first test case. Here c=50=52+42+32c = 50 = 5^2 + 4^2 + 3^2, so w=1w=1 is the answer.

Please note that the piece of cardboard goes behind each picture, not just the border.

米尔恰有 nn 张照片。第 ii 张照片是一个边长为 sis_i 厘米的正方形。

他将每张照片粘贴在一个正方形纸板上,使得每张照片四周均有宽度为 ww 厘米的纸板边框。总共,他使用了 cc 平方厘米的纸板。已知各张照片的尺寸及总纸板面积 cc,你能求出 ww 的值吗?

第一个测试用例的示意图。此处 c=50=52+42+32c = 50 = 5^2 + 4^2 + 3^2,因此答案为 w=1w=1。

请注意:纸板覆盖整张照片(即包含照片本身及其四周边框),而不仅限于边框部分。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains two positive integers nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) and cc (1≤c≤10181 \leq c \leq 10^{18}) — the number of paintings, and the amount of used square centimeters of cardboard.

The second line of each test case contains nn space-separated integers sis_i (1≤si≤1041 \leq s_i \leq 10^4) — the sizes of the paintings.

The sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

Additional constraint on the input: Such an integer ww exists for each test case.

Please note, that some of the input for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)——测试用例的数量。

每个测试用例的第一行包含两个正整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)和 cc(1≤c≤10181 \leq c \leq 10^{18})——分别为画作的数量以及所用纸板的平方厘米总数。

每个测试用例的第二行包含 nn 个以空格分隔的整数 sis_i(1≤si≤1041 \leq s_i \leq 10^4)——表示各幅画作的尺寸。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输入的额外约束:对每个测试用例,均存在满足条件的整数 ww。

请注意,某些测试用例的部分输入可能超出 32 位整数类型的表示范围,因此在编程语言中应至少使用 64 位整数类型(例如 C++ 中的 long long)。

输出格式

For each test case, output a single integer — the value of ww (w≥1w \geq 1) which was used to use exactly cc squared centimeters of cardboard.

对于每个测试用例,输出一个整数 —— 即恰好使用 cc 平方厘米纸板时所用的 ww 值(w≥1w \geq 1)。

输入输出样例

  • 输入#1

    10
    3 50
    3 2 1
    1 100
    6
    5 500
    2 2 2 2 2
    2 365
    3 4
    2 469077255466389
    10000 2023
    10 635472106413848880
    9181 4243 7777 1859 2017 4397 14 9390 2245 7225
    7 176345687772781240
    9202 9407 9229 6257 7743 5738 7966
    14 865563946464579627
    3654 5483 1657 7571 1639 9815 122 9468 3079 2666 5498 4540 7861 5384
    19 977162053008871403
    9169 9520 9209 9013 9300 9843 9933 9454 9960 9167 9964 9701 9251 9404 9462 9277 9661 9164 9161
    18 886531871815571953
    2609 10 5098 9591 949 8485 6385 4586 1064 5412 6564 8460 2245 6552 5089 8353 3803 3764

    输出#1

    1
    2
    4
    5
    7654321
    126040443
    79356352
    124321725
    113385729
    110961227

说明/提示

The first test case is explained in the statement.

For the second test case, the chosen ww was 22, thus the only cardboard covers an area of c=(2⋅2+6)2=102=100c = (2 \cdot 2 + 6)^2 = 10^2 = 100 squared centimeters.

For the third test case, the chosen ww was 44, which obtains the covered area c=(2⋅4+2)2×5=102×5=100×5=500c = (2 \cdot 4 + 2)^2 \times 5 = 10^2 \times 5 = 100 \times 5 = 500 squared centimeters.

第一个测试用例已在题目描述中说明。

对于第二个测试用例,所选的 ww 为 22,因此唯一一张纸板覆盖的面积为 c=(2⋅2+6)2=102=100c = (2 \cdot 2 + 6)^2 = 10^2 = 100 平方厘米。

对于第三个测试用例,所选的 ww 为 44,此时覆盖的面积为 c=(2⋅4+2)2×5=102×5=100×5=500c = (2 \cdot 4 + 2)^2 \times 5 = 10^2 \times 5 = 100 \times 5 = 500 平方厘米。

输入解题思路,AI测评打分。不知道怎么写?

首页