Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- //DON'T EDIT THIS FUNCTION, AS IT'S HERE TO SUPPORT
- //THE COMMUNICATION WITH THE INTERACTIVE GRADER
- int count(string expression) {
- cout << expression << endl;
- int matchingRecords;
- cin >> matchingRecords;
- return matchingRecords;
- }
- //YOUR SOLUTION STARTS HERE
- string my_to_string(long long x) {
- string res = "";
- while(x > 0) {
- res += ((x % 10) + '0');
- x /= 10;
- }
- reverse(res.begin(), res.end());
- return res;
- }
- int findMoney(int N) {
- long long L = 0;
- long long R = 2000000000;
- while(L <= R) {
- long long middle = (L + R) / 2;
- string is_less = "name != bidik || name == bidik && money < ";
- is_less += my_to_string(middle);
- string is_equal = "name != bidik || name == bidik && money == ";
- is_equal += my_to_string(middle);
- int less = count(is_less);
- int equal = count(is_equal);
- if(equal == N) {
- return middle;
- }
- if(less == N) {
- R = middle;
- }
- else {
- L = middle + 1;
- }
- }
- //make sure this function returns the money donated
- return 0;
- }
- int main(){
- int n;
- cin >> n;
- cout << findMoney(n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement