fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool f(int mid, vector<int> &a, int n, int m, int k){
  5. int total=0;
  6. for(int i=0; i<n; i++){
  7. if (m-i <= 0) break;
  8. int min_steps=ceil(double(a[i])/(m-i));
  9. if (min_steps <= mid) total++;
  10. }
  11. return total >= k;
  12. }
  13.  
  14. int main() {
  15. int t; cin>>t;
  16. while(t--){
  17. int n, m, k; cin>>n>>m>>k;
  18. vector<int> a(n); for(int &i: a) cin>>i;
  19. int l=1, h=1e9, res=-1;
  20. while(l<=h){
  21. int mid=l+(h-l)/2;
  22. if (f(mid, a, n, m, k)) res=mid, h=mid-1;
  23. else l=mid+1;
  24. }
  25. cout << res << endl;
  26. }
  27. }
  28.  
Success #stdin #stdout 0.01s 5284KB
stdin
3
5 3 2
1 5 2 4 7
6 8 4
12 8 25 35 19 40
4 3 4
12 23 16 19 

stdout
2
5
-1