Advertisement
Josif_tepe

Untitled

Mar 21st, 2025
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <queue>
  6. using namespace std;
  7. typedef long long ll;
  8. const int maxn = 2e5 + 100;
  9. int n;
  10. ll k;
  11. ll a[maxn];
  12. int main() {
  13.     cin >> n >> k;
  14.    
  15.     for(int i = 0; i < n; i++) {
  16.         cin >> a[i];
  17.     }
  18.    
  19.     ll L = 0, R = 1e18;
  20.     ll res = 1e18;
  21.     while(L <= R) {
  22.         ll middle = (L + R) / 2;
  23.        
  24.         ll sum = 0;
  25.         for(int i = 0; i < n; i++) {
  26.             sum += middle / a[i];
  27.         }
  28.         if(sum >= k) {
  29.             res = min(res, middle);
  30.             R = middle - 1;
  31.         }
  32.         else {
  33.             L = middle + 1;
  34.         }
  35.        
  36.        
  37.     }
  38.     cout << res << endl;
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement