peshopbs2

Решението на задачата с палачинките

Jul 31st, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #define MAXN 32
  4. using namespace std;
  5.  
  6. long long x, n, t[MAXN], l = 1, r, mid;
  7.  
  8. long long check(long long x){
  9.     long long cnt = 0;
  10.     for(int i = 0; i < n; i++){
  11.         cnt += floor(x/t[i]);
  12.     }
  13.     return cnt;
  14. }
  15.  
  16.  
  17. int main(){
  18.     cin >> x;
  19.     cin >> n;
  20.     for(int i = 0; i < n; i++) cin >> t[i];
  21.     l = 1;
  22.     r = x*t[0];
  23.     while(l!=r){
  24.         mid = (l+r)/2;
  25.         if(check(mid)<x){ l = mid+1;}else{
  26.             r = mid;
  27.         }
  28.     }
  29.  
  30.     cout << l << endl;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment