4 条题解
-
0
二分答案即可
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int a[N]; int n,m; int mx = -1; bool check(int x){ long long sum = 0; for (int i = 1; i <= n; ++i) { if (a[i] > x) { sum += (a[i] - x); }else{ continue; } } if (sum < m) return true; return false; } int main(){ scanf("%d %d",&n,&m); for (int i = 1; i <= n; ++i) { scanf("%d",&a[i]); mx = max(mx,a[i]); } int l = 1,r = mx; while (l + 1 < r) { int mid = (l + r)/2; if (check(mid)) { r = mid; }else { l = mid; } } printf("%d\n",l); return 0; }
信息
- ID
- 89
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 925
- 已通过
- 205
- 上传者