<Problem>
https://oj.vnoi.info/problem/bill
#include <iostream>
using namespace std;
long long getVnd(long long x) {
if (x > 1000000) return getVnd(1000000) + (x - 1000000) * 700;
if (x > 10000) return getVnd(10000) + (x - 10000) * 500;
if (x > 100) return getVnd(100) + (x - 100) * 300;
return x * 200;
}
long long getKwh(long long x) {
if (x > getVnd(1000000)) return 1000000 + (x - getVnd(1000000)) / 700;
if (x > getVnd(10000)) return 10000 + (x - getVnd(10000)) / 500;
if (x > getVnd(100)) return 100 + (x - getVnd(100)) / 300;
return x / 200;
}
int main() {
long long x, y;
cin >> x >> y;
long long total = getKwh(x);
long long low = 0, high = total / 2;
long long ans = 0;
while (low <= high) {
long long mid = (high + low) / 2;
long long temp = getVnd(total - mid) - getVnd(mid);
if (temp == y) {
ans = getVnd(mid);
break;
}
else {
if (temp < y) high = mid - 1;
else low = mid + 1;
}
}
cout << ans << endl;
return 0;
}