Advertisement
Josif_tepe

Untitled

Nov 18th, 2022
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     long long K;
  10.     cin >> K;
  11.    
  12.     int niza[n];
  13.     for(int i = 0; i < n; i++) {
  14.         cin >> niza[i];
  15.     }
  16.    
  17.     long long L = 1;
  18.     long long R = 40000000000000;
  19.     long long result = 40000000000000;
  20.     while(L <= R) {
  21.         long long middle = (L + R) / 2;
  22.        
  23.         long long resheni_zadaci = 0;
  24.         for(int i = 0; i < n; i++) {
  25.             resheni_zadaci += (middle / niza[i]);
  26.         }
  27.         if(resheni_zadaci >= K) {
  28.             R = middle - 1;
  29.             result = min(result, middle);
  30.         }
  31.         else {
  32.             L = middle + 1;
  33.         }
  34.     }
  35.     cout << result << endl;
  36.    
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement