二分
#include <bits/stdc++.h> #define int long long #define endl "\n" using namespace std; const int N = 1e5 + 50; int a[N]; int n, m, k; bool check(int x){ int sum = 0; for(int i = 1; i <= n; i++){ if(a[i] <= x){ sum = sum + (x - a[i] + k - 1) / k; } if(sum > m){ return false; } } return sum <= m; } void slove(){ cin >> n >> m >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } int l = 0, r = 2e18; while(l + 1 < r){ int m = (l + r) / 2; if(check(m)){ l = m; }else{ r = m; } } cout << l; } signed main(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); slove(); return 0; }