B. Kvass and the Fair Nut
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The Fair Nut likes kvass very much. On his birthday parents presented him nn kegs of kvass. There are vivi liters of kvass in the ii-th keg. Each keg has a lever. You can pour your glass by exactly 11 liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by ss liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by ss liters of kvass.
Input
The first line contains two integers nn and ss (1≤n≤1031≤n≤103, 1≤s≤10121≤s≤1012) — the number of kegs and glass volume.
The second line contains nn integers v1,v2,…,vnv1,v2,…,vn (1≤vi≤1091≤vi≤109) — the volume of ii-th keg.
Output
If the Fair Nut cannot pour his glass by ss liters of kvass, print −1−1. Otherwise, print a single integer — how much kvass in the least keg can be.
Examples
input
Copy
3 3 4 3 5
output
Copy
3
input
Copy
3 4 5 3 4
output
Copy
2
input
Copy
3 7 1 2 3
output
Copy
-1
Note
In the first example, the answer is 33, the Fair Nut can take 11 liter from the first keg and 22 liters from the third keg. There are 33liters of kvass in each keg.
In the second example, the answer is 22, the Fair Nut can take 33 liters from the first keg and 11 liter from the second keg.
In the third example, the Fair Nut can't pour his cup by 77 liters, so the answer is −1−1.
太容易被限制思想了……
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll a[1005];
int check(ll M){
ll sum=0;
for(int i=0;i<n;i++) sum+=(a[i]-M);
if(sum>=m) return 1;
return 0;
}
int main(){
cin>>n>>m;
ll sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
sort(a,a+n);
ll L=0,R=a[0],ans;
while(L<=R){
ll M=(L+R)/2;
if(check(M)) ans=M,L=M+1;
else R=M-1;
}
if(sum<m) cout<<"-1"<<endl;
else cout<<ans<<endl;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int n,k,a,m=99999999999,s=0;
cin>>n>>k;
for(long long int i=0;i<n;i++)
{
cin>>a;
m=min(m,a);
s+=a;
}
if(s<k)
{
cout<<-1;
}
else
{
cout<<min(m,(s-k)/n);
}
}