Advertisement
welleyth

3967. Ropes

Dec 26th, 2020
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define mp make_pair
  7. #define pb push_back
  8.  
  9. int n,k;
  10. vector<int> v;
  11.  
  12. bool F(int t)
  13. {
  14.     int tmp = 0;
  15.     for(int i=0;i<n;i++)
  16.     {
  17.         tmp += v[i]/t;
  18.     }
  19.     return tmp >= k;
  20. }
  21.  
  22. signed main() {
  23.     ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
  24.     //freopen("input.txt","r",stdin);
  25.     //freopen("output.txt","w",stdout);
  26.  
  27.     cin >> n >> k;
  28.  
  29.     v.resize(n);
  30.  
  31.     for(int i=0;i<n;i++)
  32.     {
  33.         cin >> v[i];
  34.     }
  35.  
  36.     int L = 0, R = (int)1e9;
  37.  
  38.     int mid;
  39.  
  40.     while(R - L > 1)
  41.     {
  42.         mid = (L+R)/2;
  43.         if(F(mid))
  44.             L = mid;
  45.         else
  46.             R = mid;
  47.     }
  48.  
  49.     cout << (F(R) ? R : L);
  50.  
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement