Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #define MAXN 32
- using namespace std;
- long long x, n, t[MAXN], l = 1, r, mid;
- long long check(long long x){
- long long cnt = 0;
- for(int i = 0; i < n; i++){
- cnt += floor(x/t[i]);
- }
- return cnt;
- }
- int main(){
- cin >> x;
- cin >> n;
- for(int i = 0; i < n; i++) cin >> t[i];
- l = 1;
- r = x*t[0];
- while(l!=r){
- mid = (l+r)/2;
- if(check(mid)<x){ l = mid+1;}else{
- r = mid;
- }
- }
- cout << l << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment