Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<algorithm>
- #define lli long long int
- using namespace std;
- //checks whether current number of students can be given the tokens...
- bool check(lli ans, lli m, lli x) {
- lli temp = 0;
- for (lli i = 0; i < ans; i++) {
- if (temp + x <= m)
- temp += x;
- else {
- return false;
- }
- }
- return true;
- }
- int main() {
- lli n, m, x, y;
- cin >> n >> m >> x >> y;
- lli low = 0, high = n , ans = 0, newm;
- while (low <= high) {
- lli mid = (low + high) / 2;
- if (check(mid, m, x)) {
- //new tokens = tokens we had + tokens by money from non qualifying students...
- newm = ((n - mid) * y) + m;
- ans = newm / x;
- low = mid + 1;
- }
- else
- high = mid - 1;
- }
- cout << ans;
- }
Add Comment
Please, Sign In to add comment