Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define LL long long
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n;
- LL k;
- cin >> n;
- cin >> k;
- vector<LL>a_arr(n);
- for(int i=0;i<n;i++)
- {
- cin>>a_arr[i];
- }
- LL l=0,r=1e18;
- while(l<r)
- {
- LL mid=(l+r+1)/2;
- LL ans=mid+(n-1);
- LL need=0,t=0;
- for(int i=0;i<n;i++)
- {
- if(a_arr[i]>ans/n)
- {
- t++;
- }
- else
- {
- LL tmp = ans/n-a_arr[i];
- need += tmp;
- }
- }
- need+=max(ans%n-t,0ll);
- if(need<=k)l=mid;
- else r=mid-1;
- }
- cout<<l;
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement