Advertisement
Josif_tepe

Untitled

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