思路:
二分。
实现:
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 typedef long long ll; 5 const int MAXN = 100005; 6 int a[MAXN], n, k; 7 int Ceil(int a, int c) 8 { 9 return (a + c - 1) / c; 10 } 11 bool check(int x) 12 { 13 ll tot = 0; 14 for (int i = 0; i < n; i++) 15 { 16 if (a[i] > x) tot += Ceil(a[i] - x, k - 1); 17 if (tot > x) return false; 18 } 19 return true; 20 } 21 int main() 22 { 23 scanf("%d", &n); 24 int maxn = 0; 25 for (int i = 0; i < n; i++) 26 { 27 scanf("%d", &a[i]); 28 maxn = max(maxn, a[i]); 29 } 30 scanf("%d", &k); 31 if (k == 1) { printf("%d ", maxn); return 0; } 32 int l = 1, r = maxn, ans = maxn; 33 while (l <= r) 34 { 35 int m = (l + r) >> 1; 36 if (check(m)) 37 { 38 ans = m; r = m - 1; 39 } 40 else l = m + 1; 41 } 42 printf("%d ", ans); 43 return 0; 44 }