Advertisement
erfanul007

UVa 1648

Sep 16th, 2021
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long int
  5.  
  6. int BSlo(int n, int u, int d){
  7.     int lo = 0, hi = n, mid, ans;
  8.  
  9.     while(lo <= hi){
  10.         mid = (lo + hi)/2;
  11.         int floor = (u * mid) - (d * (n-mid));
  12.         if(floor > 0){
  13.             ans = floor;
  14.             hi = mid -1;
  15.         }
  16.         else{
  17.             lo = mid + 1;
  18.         }
  19.     }
  20.     return ans;
  21. }
  22.  
  23. int main(){
  24.     #ifdef ERFANUL007
  25.         clock_t tStart = clock();
  26.         freopen("input.txt", "r", stdin);
  27.         freopen("output.txt", "w", stdout);
  28.     #endif
  29.  
  30.     int n, m;
  31.     while(cin >> n >> m){
  32.         int ans = INT_MAX;
  33.    
  34.         while(m--){
  35.             int u, d;
  36.             cin >> u >> d;
  37.             ans = min(ans, BSlo(n, u, d));
  38.         }
  39.         cout << ans << '\n';
  40.     }
  41.  
  42.     #ifdef ERFANUL007
  43.         fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  44.     #endif
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement