Guest User

Untitled

a guest
Jun 9th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<algorithm>
  4. #define lli long long int
  5.  
  6. using namespace std;
  7.  
  8. //checks whether current number of students can be given the tokens...
  9. bool check(lli ans, lli m, lli x) {
  10.     lli temp = 0;
  11.     for (lli i = 0; i < ans; i++) {
  12.         if (temp + x <= m)
  13.             temp += x;
  14.         else {
  15.             return false;
  16.         }
  17.     }
  18.     return true;
  19. }
  20.  
  21. int main() {
  22.     lli n, m, x, y;
  23.     cin >> n >> m >> x >> y;
  24.  
  25.     lli low = 0, high = n , ans = 0, newm;
  26.     while (low <= high) {
  27.         lli mid = (low + high) / 2;
  28.         if (check(mid, m, x)) {
  29.             //new tokens = tokens we had + tokens by money from non qualifying students...
  30.             newm = ((n - mid) * y) + m;
  31.             ans = newm / x;
  32.             low = mid + 1;
  33.         }
  34.         else
  35.             high = mid - 1;
  36.     }
  37.  
  38.     cout << ans;
  39. }
Add Comment
Please, Sign In to add comment