#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
using namespace std;
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vc vector
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define int ll
const int N = 5e5 + 5;
const int M = 5e5 + 5;
const int mod = 1e9 + 7;
const int block = 500;
int n;
ll a[N], b[N], pref[N];
void solve() {
cin >> n;
vc <pair<ll,ll>> save;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i] >> b[i];
save.pb(mp(a[i],b[i]));
}
sort(all(save));
ll ans = save[0].se + save[0].fi;
ll res = save[0].se;
for ( int i = 2; i <= n; i++ ) {
ans += save[i-1].se;
ll sum = save[i-1].se + save[i-1].fi;
if ( sum > ans ) {
ans = sum;
}
res = max(res,ans-save[i-1].fi);
}
cout << res;
}
signed main() {
speed;
int tt;
//cin >> tt;
tt = 1;
while ( tt-- ) {
solve();
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
4444 KB |
Output is correct |
26 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
4444 KB |
Output is correct |
26 |
Correct |
0 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4592 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4696 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
2 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4780 KB |
Output is correct |
45 |
Correct |
2 ms |
4700 KB |
Output is correct |
46 |
Correct |
1 ms |
4700 KB |
Output is correct |
47 |
Correct |
2 ms |
4700 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4700 KB |
Output is correct |
50 |
Correct |
1 ms |
4700 KB |
Output is correct |
51 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Correct |
0 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
0 ms |
4444 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
0 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
4444 KB |
Output is correct |
26 |
Correct |
0 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4696 KB |
Output is correct |
32 |
Correct |
1 ms |
4592 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4696 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
2 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
1 ms |
4700 KB |
Output is correct |
41 |
Correct |
2 ms |
4700 KB |
Output is correct |
42 |
Correct |
1 ms |
4700 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4780 KB |
Output is correct |
45 |
Correct |
2 ms |
4700 KB |
Output is correct |
46 |
Correct |
1 ms |
4700 KB |
Output is correct |
47 |
Correct |
2 ms |
4700 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4700 KB |
Output is correct |
50 |
Correct |
1 ms |
4700 KB |
Output is correct |
51 |
Correct |
1 ms |
4696 KB |
Output is correct |
52 |
Correct |
97 ms |
18372 KB |
Output is correct |
53 |
Correct |
102 ms |
30392 KB |
Output is correct |
54 |
Correct |
110 ms |
30392 KB |
Output is correct |
55 |
Correct |
108 ms |
30644 KB |
Output is correct |
56 |
Correct |
103 ms |
30560 KB |
Output is correct |
57 |
Correct |
104 ms |
30392 KB |
Output is correct |
58 |
Correct |
104 ms |
30392 KB |
Output is correct |
59 |
Correct |
101 ms |
30540 KB |
Output is correct |
60 |
Correct |
102 ms |
30392 KB |
Output is correct |
61 |
Correct |
106 ms |
30392 KB |
Output is correct |
62 |
Correct |
108 ms |
30488 KB |
Output is correct |
63 |
Correct |
108 ms |
30388 KB |
Output is correct |
64 |
Correct |
103 ms |
30392 KB |
Output is correct |
65 |
Correct |
101 ms |
30552 KB |
Output is correct |
66 |
Correct |
103 ms |
30644 KB |
Output is correct |
67 |
Correct |
101 ms |
30392 KB |
Output is correct |
68 |
Correct |
102 ms |
30536 KB |
Output is correct |