Advertisement
Josif_tepe

Untitled

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