1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int n, m; int a[1123456]; bool check(int x) { long long sum = 0; for (int i = 1; i <= n; i++) if (a[i] > x) sum += a[i] - x; return sum >= m; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; int l = 0; int r = 0; for (int i = 1; i <= n; i++) r = max(r, a[i]); int ans; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << "\n"; return 0; }
- 1
信息
- ID
- 1316
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 17
- 已通过
- 7
- 上传者