https://atcoder.jp/contests/abc203/tasks/abc203_c
解説
https://atcoder.jp/contests/abc203/submissions/23075028
int N, K; vector<pair<ll, ll>> AB; //--------------------------------------------------------------------------------------------------- ll solve() { ll yen = K; ll x = 0; fore(p, AB) { ll A = p.first; ll B = p.second; if (yen < A - x) return x + yen; yen -= A - x; x = A; yen += B; } return x + yen; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> K; rep(i, 0, N) { ll a, b; cin >> a >> b; AB.push_back({ a, b }); } sort(all(AB)); cout << solve() << endl; }