1 solutions
-
0
#include<iostream> #include<algorithm> using namespace std; int a[10008000]; int n,m; bool find(int x) { long long s = 0; for(int i = 1;i <= n;i++){ if(a[i] > x)s=s+a[i]-x; } if(s >= m) return true; //若是把它放在循环外面,s最好开long long 要不然有可能会超过范围 return false; } int sum_m() { int l = a[1],r = a[n]; while(l < r) { int mid = l+r+1>>1; //cout<<mid<<" "<<p<<' '<<u<<endl; if(find(mid)) l = mid; else r = mid - 1 ; } return l; } int main() { cin.tie(0); cin>>n>>m; for(int i = 1;i <= n;i++) { cin>>a[i]; } sort(a+1,a+n+1); int h = sum_m(); printf("%d",h); return 0; }
- 1
Information
- ID
- 1244
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 83
- Accepted
- 21
- Uploaded By