Problem:
いちご (Strawberry)
問題文
Just Oishi Ichigo 農園 (以下 JOI 農園) は東西に細長いことで有名ないちご農園であり，その入り口は農園の最も西にある．以下では，入り口から東に
k
メートル進んだ場所を地点
k
と呼ぶことにする．
JOI 農園内には
N
個のいちごがなっている．それぞれ
1
から
N
の番号がつけられている．どのいちごも時刻
0
までは青い．いちご
i
(
1 ≦ i ≦ N
) は地点
A
i
に実をつけており，時刻
T
i
になると熟し赤い状態になる．
いちごは青い状態では収穫できない．つまり，いちご
i
は時刻
T
i
となるまで収穫できない．あなたは時刻
0
に地点
0
にある農園の入り口から出発して，最大秒速
1
メートルで東西方向に移動しながらいちごを収穫する．いちごを収穫するのにかかる時間は無視できるとする．
いちご農園についての情報が与えられるので，すべてのいちごを赤い状態で収穫したあと入り口に帰ってくるまでにかかる時間の最小値を求めるプログラムを作成せよ．
制約
1 ≦ N ≦ 100 000
．
0 ≦ A
i
≦ 1 000 000 000 (= 10
9
)
(
1 ≦ i ≦ N
)．
0 ≦ T
i
≦ 1 000 000 000 (= 10
9
)
(
1 ≦ i ≦ N
)．
入力される値はすべて整数である．
入力
入力は以下の形式で標準入力から与えられる．
N
A
1
T
1
A
2
T
2
:
A
N
T
N
出力
すべてのいちごを赤い状態で収穫したあと入り口に帰ってくるまでにかかる時間の最小値を
1
行に出力せよ．
入出力例
入力例 1
10
1 3
2 1
3 4
4 1
5 5
6 9
7 2
8 6
9 5
10 3
出力例 1
20
はじめの
10
秒かけて地点
10
まで移動すると，その道中でいちご
2, 4, 5, 7, 8, 9, 10
をこの順に収穫することができる．その後
10
秒かけて地点
0
まで戻ると，その道中でいちご
6, 3, 1
をこの順に収穫することができる．これで
10
個すべてのいちごを赤い状態で収穫することができる．
入力例 2
10
0 450
5 445
10 430
15 405
20 370
25 325
30 270
35 205
40 130
45 45
出力例 2
450
以下のように移動すると
450
秒ですべてのいちごを赤い状態で収穫できる．
45
秒かけて地点
45
まで移動する．このとき時刻
45
なのでいちご
10
を収穫できる．収穫後
45
秒かけて地点
0
まで移動する．
その後，
40
秒かけて地点
40
まで移動する．このとき時刻
130
なのでいちご
9
を収穫できる．収穫後
40
秒かけて地点
0
まで移動する．
その後，
35
秒かけて地点
35
まで移動する．このとき時刻
205
なのでいちご
8
を収穫できる．収穫後
35
秒かけて地点
0
まで移動する．
その後，
30
秒かけて地点
30
まで移動する．このとき時刻
270
なのでいちご
7
を収穫できる．収穫後
30
秒かけて地点
0
まで移動する．
その後，
25
秒かけて地点
25
まで移動する．このとき時刻
325
なのでいちご
6
を収穫できる．収穫後
25
秒かけて地点
0
まで移動する．
その後，
20
秒かけて地点
20
まで移動する．このとき時刻
370
なのでいちご
5
を収穫できる．収穫後
20
秒かけて地点
0
まで移動する．
その後，
15
秒かけて地点
15
まで移動する．このとき時刻
405
なのでいちご
4
を収穫できる．収穫後
15
秒かけて地点
0
まで移動する．
その後，
10
秒かけて地点
10
まで移動する．このとき時刻
430
なのでいちご
3
を収穫できる．収穫後
10
秒かけて地点
0
まで移動する．
その後，
5
秒かけて地点
5
まで移動する．このとき時刻
445
なのでいちご
2
を収穫できる．収穫後
5
秒かけて地点
0
まで移動する．
ちょうど時刻
450
に地点
0
に到達するので，いちご
1
を収穫できる．すべてのいちごを収穫すると同時に地点
0
に到着した．
入力例 3
15
11 23
3 94
89 3
38 58
65 29
41 3
80 42
22 76
48 85
83 98
87 29
97 96
22 75
57 25
99 33
出力例 3
198
情報オリンピック日本委員会
作 『第 19 回日本情報オリンピック JOI 2019/2020 一次予選競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<utility>
#include<set>
#include<deque>
#include <unordered_map>
#include<string>
#include<cmath>

using namespace std;

int MIN = -1e9;
const int MOD = 10000;

int main() {
	int N;
	cin >> N;
	int mans = 0;
	for (int i = 0; i < N; i++) {
		int a, t;
		cin >> a >> t;
		t = max(a, t);
		mans = max(mans, t + a);
	}

	cout << mans<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3428
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<pair<ll,ll>> p(N);
    rep(i,N) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());

    ll x = max(p.back().first, p.back().second);
    for(int i = N - 2; i >= 0; i--) {
        x = max(x + p[i + 1].first - p[i].first, p[i].second);
    }
    cout << x + p[0].first << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4660
final_rank: 7

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
struct k{
	int a, t;
};
bool cmp(k a, k b){
	return a.a>b.a;
}
k k[100000]={};
int main(){
	int n, l=0;
	
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d %d", &k[i].a, &k[i].t);
		l=max(l, k[i].a);
	}
	sort(k, k+n, cmp);
	int t=l, b=l;
	for(int i=0; i<n; i++){
		t+=b-k[i].a;
		b=k[i].a;
		if(t<k[i].t) t=k[i].t;
	}
	printf("%d\n", t+b);
}
accuracy: 1
time_ms: 10
memory_kb: 3768
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 707;

void start() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    // freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
}

struct dl {
    ll a, b;
} a[200005];

bool cmp(dl a,dl b) {
    if(a.a == b.a) return a.b > b.b;
    return a.a < b.a;
}

ll n;
int main() 
{
    start();
    cin >> n;
    for(int i=1; i<=n; ++i)
        cin >> a[i].a >> a[i].b;
    sort(a+1,a+n+1,cmp);
    ll ok = a[n].a;
    
    a[n+1].a = a[n].a;
    a[0].a = 0; a[0].b = 0;
    
    int i = n;
    while(i >= 0) {
        ok = max(ok + a[i+1].a-a[i].a, a[i].b);
        --i;
    }
    cout << ok << '\n';
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5012
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
bool bao[N]; int n; pair <int, int> pr[N];

void solve () {
    cin >> n;
    pr[0] = {0, 0};
    for (int i = 1; i <= n; ++i) {
        cin >> pr[i].first >> pr[i].second;
    }
    sort (pr + 1, pr + n + 1);
    int tg = pr[n].first;
    for (int i = n; i >= 1; --i) {
        if (tg >= pr[i].second) {
            tg += (pr[i].first - pr[i - 1].first);
        }
        else {
            tg = pr[i].second;
        }
    }
    cout << tg << "\n";
}

int main () {
	#define file "ILYBVM"
	if (fopen(file".inp","r")) {
		freopen(file".inp","r",stdin);
		freopen(file".out","w",stdout);
	}
	cin.tie(0) -> sync_with_stdio(0);
	cout.tie(0) -> sync_with_stdio(0);
	int q = 1;
	// cin >> q;
	while (q--) {
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4232
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)

using ll = long long;

const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;

void _27augain(void) {
  int n;
  cin >> n;
  ll res = 0, mx = 0;
  for (int i = 0; i < n; ++i) {
    ll a, t;
    cin >> a >> t;
    mx = max(mx, a);
    res = max({res, a + t, mx * 2});
  }  
  cout << res << "\n";
}

int32_t main(void) {
#define task "_27augain"
  cin.tie(0)->sync_with_stdio(0);
  for (string iext : {"in", "inp"}) {
    if (fopen((task "." + iext).c_str(), "r")) {
      freopen((task "." + iext).c_str(), "r", stdin);
      freopen(task ".out", "w", stdout);
    }
  }
  int testcase = 1;
  // cin >> testcase;
  while (testcase--) { 
    _27augain();
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3504
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define i32 int32_t
#define ll long long
#define ldb long double
#define pb push_back
#define sz size()
#define el '\n'
#define BIT(x,i) (((x)>>(i))&1)
#define pll pair<ll,ll>
#define pii pair<int,int>

const int mod = 1e9 + 7;

int n;
pll x[100005];
ll a[100005] , t[100005];
ll dp[100005];

void solve() {
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        cin >> x[i].fi >> x[i].se;
    }
    sort(x + 1 , x + 1 + n);
    for(int i = 1 ; i <= n ; i++){
        a[i] = x[i].fi;
        t[i] = x[i].se;
    }
    dp[n] = max(a[n] , t[n]);
    for(int i = n-1 ; i >= 1 ; i--){
        if(dp[i+1] + a[i+1] - a[i] < t[i]) {
            dp[i] = t[i];
        }
        else dp[i] = dp[i+1] + a[i+1] - a[i];
    }
    cout << dp[1] + a[1] << el;
}

i32 main() {
#define TASKNAME "betterdayswillcome"
    if (fopen(TASKNAME ".inp", "r")) {
        freopen(TASKNAME ".inp", "r", stdin);
        freopen(TASKNAME ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int testt = 1;
    while (testt--) {
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7372
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define st first
#define nd second

int main() {
//        freopen("CHAND.inp", "r", stdin);
//        freopen("CHAND.out", "w", stdout);
        int n;
        cin >> n;
        int ans = 0, a, t;
        for (int i = 0; i < n; i++) {
                cin >> a >> t;
                ans = max(ans, max(a, t) + a);
        }
        cout << ans << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 3432
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long

int n;
pair <int, int> p[N];
ll dp[N];

int main(){
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
	sort(p + 1, p + n + 1);
	dp[n] = max(p[n].first, p[n].second);
	for (int i = n - 1; i >= 1; i--) {
		dp[i] = max(dp[i + 1] + p[i + 1].first - p[i].first, (ll)p[i].second);
	}	
	cout << dp[1] + p[1].first << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 4700
final_rank: 16

code_snippet: #include <iostream>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	unsigned int N, i, A, T, R, ans = 0;
	cin >> N;

	for (i = 0; i != N; ++i)
	{
		cin >> A >> T;
		R = max(A, T) + A;
		if (R > ans) ans = R;
	}

	cout << ans << '\n';
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 1

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, A, T;
  cin >> N;
  vc<pi> AT(N);
  rep(i, N) {
    cin >> A >> T;
    AT[i] = mp(A, T);
  }
  sort(all(AT));
  ll ans = max(AT[N-1].fi, AT[N-1].se);
  rrep(i, N-1) {
    ans += AT[i+1].fi - AT[i].fi;
    chmax(ans, AT[i].se);
  }
  ans += AT[0].fi;
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4664
final_rank: 8

code_snippet: #line 1 "a.cpp"
#define PROBLEM ""
#line 2 "/home/kuhaku/home/github/algo/lib/template/template.hpp"
#pragma GCC target("sse4.2,avx2,bmi2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
    return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
    return (T)b < a ? a = (T)b, true : false;
}
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
constexpr double PI = M_PI;
#line 3 "/home/kuhaku/home/github/algo/lib/template/macro.hpp"
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
#line 3 "/home/kuhaku/home/github/algo/lib/template/sonic.hpp"
struct Sonic {
    Sonic() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }

    constexpr void operator()() const {}
} sonic;
#line 5 "/home/kuhaku/home/github/algo/lib/template/atcoder.hpp"
using ll = int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
    for (T &i : v) is >> i;
    return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto it = v.begin(); it != v.end(); ++it) {
        os << (it == v.begin() ? "" : " ") << *it;
    }
    return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
    else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
    if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
    else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
template <typename T, typename... Args>
auto make_vector(T x, int arg, Args... args) {
    if constexpr (sizeof...(args) == 0) return std::vector<T>(arg, x);
    else return std::vector(arg, make_vector<T>(x, args...));
}
void setp(int n) {
    std::cout << std::fixed << std::setprecision(n);
}
void Yes(bool is_correct = true) {
    std::cout << (is_correct ? "Yes" : "No") << '\n';
}
void No(bool is_not_correct = true) {
    Yes(!is_not_correct);
}
void YES(bool is_correct = true) {
    std::cout << (is_correct ? "YES" : "NO") << '\n';
}
void NO(bool is_not_correct = true) {
    YES(!is_not_correct);
}
void Takahashi(bool is_correct = true) {
    std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n';
}
void Aoki(bool is_not_correct = true) {
    Takahashi(!is_not_correct);
}
#line 3 "a.cpp"

int main(void) {
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ll a, t;
        cin >> a >> t;
        chmax(ans, max(a, t) + a);
    }
    co(ans);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, time = 0;
    cin >> n;
    int a, t;
    vector<vector<int> > berry(n, vector<int>(2));
    for (int i = 0; i < n; i++)
    {
        cin >> a >> t;
        berry[i][0] = a;
        berry[i][1] = t;
    }
    sort(berry.begin(), berry.end());
    time += berry[n - 1][0];
    for (int i = n - 2; i >= 0; i--)
    {
        time += berry[i + 1][0] - berry[i][0];
        if (time < berry[i][1])
            time += berry[i][1] - time;
    }
    time += berry[0][0];
    cout << time << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 8428
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, time = 0;
    cin >> n;
    int a, t;
    vector<vector<int>> berry(n, vector<int>(2));
    for (int i = 0; i < n; i++)
    {
        cin >> a >> t;
        berry[i][0] = a;
        berry[i][1] = t;
    }
    sort(berry.begin(), berry.end());
    time += berry[n - 1][0];
    for (int i = n - 2; i >= 0; i--)
    {
        time += berry[i + 1][0] - berry[i][0];
        if (time < berry[i][1])
            time += berry[i][1] - time;
    }
    time += berry[0][0];
    cout << time << endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 8648
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n, timer;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(2));
    int t;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i][0] >> t;
        a[i][1] = t;
    }
    sort(a.begin(), a.end());
    timer = a[n - 1][0];
    if (a[n - 1][1] > timer)
        timer += a[n - 1][1] - timer;
    for (int i = n - 2; i >= 0; i--)
    {
        timer += a[i + 1][0] - a[i][0];
        if (a[i][1] > timer)
            timer += a[i][1] - timer;
    }
    timer += a[0][0];
    cout << timer << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 8576
final_rank: 17

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n, timer;
    cin >> n;
    vector<int> a(n);
    int t[n][2];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> t[i][0];
        t[i][1] = i;
    }
    sort(a.begin(), a.end());
    timer = a[n - 1];
    if (t[n - 1][0] > timer)
        timer += t[n - 1][0] - timer;
    for (int i = n - 2; i >= 0; i--)
    {
        timer += a[i + 1] - a[i];
        if (t[i][0] > timer)
            timer += t[i][0] - timer;
    }
    timer += a[0];
    cout << timer << endl;
}
accuracy: 0.2826086956521739
time_ms: 50
memory_kb: 3784
final_rank: 20

code_snippet: //#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
  return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
  vector<T>inv(ord.size());
  for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
  return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
	ll n;cin>>n;
	vector<ll>a(n),t(n);
	rep(i,0,n)cin>>a[i]>>t[i];
	ll now=0;
	auto ord=descend(a);
	ll pos=0;
	for(auto i:ord){
		//cout<<now spa pos<<endl;
		now=max(t[i],now+abs(a[i]-pos));
		pos=a[i];
	}
	cout<<now+pos<<endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5200
final_rank: 12

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0673.cc: いちご (Strawberry)
 */

#include<cstdio>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int a, t;
    scanf("%d%d", &a, &t);
    ps[i] = pii(a, t);
  }
  sort(ps, ps + n);

  int t = ps[n - 1].first, pa = ps[n - 1].first;
  for (int i = n - 1; i >= 0; i--) {
    t = max(t + (pa - ps[i].first), ps[i].second);
    pa = ps[i].first;
  }

  t += pa;

  printf("%d\n", t);

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3740
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
    int N,an=0,M=0;
    cin>>N;
    vector<pair<int,int>> P(N);
    rep(i,N){cin>>P[i].first>>P[i].second;M=max(M,P[i].first*2);}
    rep(i,N)an=max(an,P[i].second+P[i].first-M);
    cout<<an+M<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3892
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
    int N,an=0;
    cin>>N;
    vector<pair<int,int>> P(N);
    rep(i,N)cin>>P[i].first>>P[i].second;
    sort(P.begin(),P.end());
    rep(i,N)an=max(an,P[i].second+P[i].first-P[N-1].first*2);
    cout<<an+P[N-1].first*2<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 3896
final_rank: 14