-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1850E.cpp
59 lines (41 loc) · 773 Bytes
/
1850E.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
void solve() {
int n, k;
cin >> n >> k;
vector<int>a(n);
for (int i = 0; i < n; ++i){
cin>>a[i];
}
int l = 1;
int r = 1e9;
while(l<=r){
int m = (l+r)/2;
int sum = 0;
for (int i = 0; i < n; ++i){
sum += (a[i]+2*m)*(a[i]+2*m);
if (sum > k) break;
}
if(sum==k){
cout<<m<<endl;
break;
}
if(sum>k){
r = m-1;
}
else{
l = m + 1;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}