fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25. bool isPossible(int n, int k, int mid){
  26. int ct = 0;
  27. for(int i=0; i<n; i++){
  28. ct += (a[i]+mid-1)/mid;
  29. }
  30. return ct <= k;
  31. }
  32. void consistency(int n, int k){
  33.  
  34. int s = 1, e = INF;
  35. while(s<e){
  36. int mid = s + (e-s)/2;
  37. if(isPossible(n, k, mid)){
  38. e = mid;
  39. }
  40. else s = mid+1;
  41. }
  42.  
  43. cout << s << endl;
  44.  
  45. }
  46.  
  47. void solve() {
  48.  
  49. int n, k;
  50. cin>>n >> k;
  51.  
  52. a.resize(n);
  53. for(int i=0; i<n; i++) cin >> a[i];
  54.  
  55. consistency(n, k);
  56.  
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. int32_t main() {
  65. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  66.  
  67. int t = 1;
  68. cin >> t;
  69. while (t--) {
  70. solve();
  71. }
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 5316KB
stdin
2
3 4
1 2 3
4 5
4 3 2 7
stdout
2
4