BILL - Hóa đơn tiền điện
Tác giả: RR
Ngôn ngữ: C++
#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define FORN(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
#define DOWN(i,a,b) for(int i=a,_b=(b);i>=_b;i--)
#define SET(a,v) memset(a,v,sizeof(a))
#define sqr(x) ((x)*(x))
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;
//Buffer reading
int INP,AM,REACHEOF;
#define BUFSIZE (1<<12)
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
if(!*inp) { \
if (REACHEOF) return 0;\
memset(BUF,0,sizeof BUF);\
int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
if (inpzzz != BUFSIZE) REACHEOF = true;\
inp=BUF; \
} \
INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
AM=0;\
GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
if (INP=='-') {AM=1;GETCHAR(INP);} \
j=INP-'0'; GETCHAR(INP); \
while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
if (AM) j=-j;\
}
//End of buffer reading
const long double PI = acos((long double) -1.0);
long long conv(long long x) {
long long res = 0;
res += min(x, 100LL) * 200;
x -= 100;
if (x <= 0) return res;
res += min(x, 10000LL - 100) * 300;
x -= 10000 - 100;
if (x <= 0) return res;
res += min(x, 1000000LL - 10000) * 500;
x -= 1000000 - 10000;
if (x <= 0) return res;
res += x * 700;
return res;
}
long long rev(long long x) {
long long res = 0;
if (x <= 100 * 200) return x / 200;
res += 100;
x -= 100 * 200;
if (x <= (10000 - 100) * 300) return res + x / 300;
res = 10000;
x -= (10000 - 100) * 300;
if (x <= (1000000 - 10000) * 500) return res + x / 500;
res = 1000000;
x -= (1000000 - 10000) * 500;
return x / 700 + res;
}
int main() {
long long x, y;
while (cin >> x >> y) {
long long sum = rev(x);
FOR(i,1,sum/2) {
long long a = conv(i);
long long b = conv(sum-i);
if (b-a == y) {
cout << a << endl;
break;
}
}
}
return 0;
}