#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MAX=5*1e5+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
ll a, b, cale=0, mmin=1e16, mmax=0;
vector<pair<ll, ll>> prace;
for (int i=0; i<n; i++){
cin >> a >> b;
cale += b;
mmin = min(mmin, a);
mmax = max(mmax, a);
prace.push_back({a, b});
}
cale -= (mmax-mmin);
sort(prace.begin(), prace.end());
pair<ll, ll> pref[MAX];
pair<ll, ll> suf[MAX];
pref[0] = {0, 0};
for (int i=1; i<n; i++){
pref[i].first = pref[i-1].first - prace[i-1].second+(prace[i].first-prace[i-1].first);
pref[i].second = max(pref[i].first, pref[i-1].second);
}
suf[n] = {0, 0};
for (int i=n-2; i>0; i--){
suf[i].first = suf[i+1].first - prace[i+1].second+(prace[i+1].first-prace[i].first);
suf[i].second = max(suf[i].first, suf[i+1].second);
}
ll wyn=0;
for (int i=0; i<=n; i++){
wyn = max(wyn, pref[i].second+suf[i].second);
}
cout << cale+wyn << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15952 KB |
Output is correct |
2 |
Correct |
15 ms |
15952 KB |
Output is correct |
3 |
Correct |
15 ms |
15952 KB |
Output is correct |
4 |
Correct |
17 ms |
15952 KB |
Output is correct |
5 |
Correct |
15 ms |
15924 KB |
Output is correct |
6 |
Correct |
14 ms |
15952 KB |
Output is correct |
7 |
Correct |
15 ms |
15952 KB |
Output is correct |
8 |
Correct |
15 ms |
15968 KB |
Output is correct |
9 |
Correct |
16 ms |
16056 KB |
Output is correct |
10 |
Correct |
15 ms |
15952 KB |
Output is correct |
11 |
Correct |
15 ms |
15952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15952 KB |
Output is correct |
2 |
Correct |
15 ms |
15952 KB |
Output is correct |
3 |
Correct |
15 ms |
15952 KB |
Output is correct |
4 |
Correct |
17 ms |
15952 KB |
Output is correct |
5 |
Correct |
15 ms |
15924 KB |
Output is correct |
6 |
Correct |
14 ms |
15952 KB |
Output is correct |
7 |
Correct |
15 ms |
15952 KB |
Output is correct |
8 |
Correct |
15 ms |
15968 KB |
Output is correct |
9 |
Correct |
16 ms |
16056 KB |
Output is correct |
10 |
Correct |
15 ms |
15952 KB |
Output is correct |
11 |
Correct |
15 ms |
15952 KB |
Output is correct |
12 |
Correct |
17 ms |
15952 KB |
Output is correct |
13 |
Correct |
15 ms |
15884 KB |
Output is correct |
14 |
Correct |
18 ms |
15968 KB |
Output is correct |
15 |
Correct |
16 ms |
15936 KB |
Output is correct |
16 |
Correct |
14 ms |
15952 KB |
Output is correct |
17 |
Correct |
15 ms |
16004 KB |
Output is correct |
18 |
Correct |
13 ms |
15952 KB |
Output is correct |
19 |
Correct |
13 ms |
15952 KB |
Output is correct |
20 |
Correct |
13 ms |
15952 KB |
Output is correct |
21 |
Correct |
13 ms |
15952 KB |
Output is correct |
22 |
Correct |
14 ms |
16068 KB |
Output is correct |
23 |
Correct |
13 ms |
15952 KB |
Output is correct |
24 |
Correct |
13 ms |
15952 KB |
Output is correct |
25 |
Correct |
13 ms |
15952 KB |
Output is correct |
26 |
Correct |
13 ms |
15952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15952 KB |
Output is correct |
2 |
Correct |
15 ms |
15952 KB |
Output is correct |
3 |
Correct |
15 ms |
15952 KB |
Output is correct |
4 |
Correct |
17 ms |
15952 KB |
Output is correct |
5 |
Correct |
15 ms |
15924 KB |
Output is correct |
6 |
Correct |
14 ms |
15952 KB |
Output is correct |
7 |
Correct |
15 ms |
15952 KB |
Output is correct |
8 |
Correct |
15 ms |
15968 KB |
Output is correct |
9 |
Correct |
16 ms |
16056 KB |
Output is correct |
10 |
Correct |
15 ms |
15952 KB |
Output is correct |
11 |
Correct |
15 ms |
15952 KB |
Output is correct |
12 |
Correct |
17 ms |
15952 KB |
Output is correct |
13 |
Correct |
15 ms |
15884 KB |
Output is correct |
14 |
Correct |
18 ms |
15968 KB |
Output is correct |
15 |
Correct |
16 ms |
15936 KB |
Output is correct |
16 |
Correct |
14 ms |
15952 KB |
Output is correct |
17 |
Correct |
15 ms |
16004 KB |
Output is correct |
18 |
Correct |
13 ms |
15952 KB |
Output is correct |
19 |
Correct |
13 ms |
15952 KB |
Output is correct |
20 |
Correct |
13 ms |
15952 KB |
Output is correct |
21 |
Correct |
13 ms |
15952 KB |
Output is correct |
22 |
Correct |
14 ms |
16068 KB |
Output is correct |
23 |
Correct |
13 ms |
15952 KB |
Output is correct |
24 |
Correct |
13 ms |
15952 KB |
Output is correct |
25 |
Correct |
13 ms |
15952 KB |
Output is correct |
26 |
Correct |
13 ms |
15952 KB |
Output is correct |
27 |
Correct |
14 ms |
16208 KB |
Output is correct |
28 |
Correct |
14 ms |
16208 KB |
Output is correct |
29 |
Correct |
14 ms |
16208 KB |
Output is correct |
30 |
Correct |
14 ms |
16240 KB |
Output is correct |
31 |
Correct |
14 ms |
16208 KB |
Output is correct |
32 |
Correct |
19 ms |
16208 KB |
Output is correct |
33 |
Correct |
14 ms |
16208 KB |
Output is correct |
34 |
Correct |
14 ms |
16208 KB |
Output is correct |
35 |
Correct |
18 ms |
16304 KB |
Output is correct |
36 |
Correct |
14 ms |
16208 KB |
Output is correct |
37 |
Correct |
14 ms |
16208 KB |
Output is correct |
38 |
Correct |
14 ms |
16120 KB |
Output is correct |
39 |
Correct |
14 ms |
16208 KB |
Output is correct |
40 |
Correct |
14 ms |
16376 KB |
Output is correct |
41 |
Correct |
14 ms |
16208 KB |
Output is correct |
42 |
Correct |
14 ms |
16376 KB |
Output is correct |
43 |
Correct |
16 ms |
16220 KB |
Output is correct |
44 |
Correct |
17 ms |
16376 KB |
Output is correct |
45 |
Correct |
19 ms |
16104 KB |
Output is correct |
46 |
Correct |
15 ms |
16208 KB |
Output is correct |
47 |
Correct |
16 ms |
16208 KB |
Output is correct |
48 |
Correct |
16 ms |
16208 KB |
Output is correct |
49 |
Correct |
16 ms |
16292 KB |
Output is correct |
50 |
Correct |
16 ms |
16208 KB |
Output is correct |
51 |
Correct |
16 ms |
16208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15952 KB |
Output is correct |
2 |
Correct |
15 ms |
15952 KB |
Output is correct |
3 |
Correct |
15 ms |
15952 KB |
Output is correct |
4 |
Correct |
17 ms |
15952 KB |
Output is correct |
5 |
Correct |
15 ms |
15924 KB |
Output is correct |
6 |
Correct |
14 ms |
15952 KB |
Output is correct |
7 |
Correct |
15 ms |
15952 KB |
Output is correct |
8 |
Correct |
15 ms |
15968 KB |
Output is correct |
9 |
Correct |
16 ms |
16056 KB |
Output is correct |
10 |
Correct |
15 ms |
15952 KB |
Output is correct |
11 |
Correct |
15 ms |
15952 KB |
Output is correct |
12 |
Correct |
17 ms |
15952 KB |
Output is correct |
13 |
Correct |
15 ms |
15884 KB |
Output is correct |
14 |
Correct |
18 ms |
15968 KB |
Output is correct |
15 |
Correct |
16 ms |
15936 KB |
Output is correct |
16 |
Correct |
14 ms |
15952 KB |
Output is correct |
17 |
Correct |
15 ms |
16004 KB |
Output is correct |
18 |
Correct |
13 ms |
15952 KB |
Output is correct |
19 |
Correct |
13 ms |
15952 KB |
Output is correct |
20 |
Correct |
13 ms |
15952 KB |
Output is correct |
21 |
Correct |
13 ms |
15952 KB |
Output is correct |
22 |
Correct |
14 ms |
16068 KB |
Output is correct |
23 |
Correct |
13 ms |
15952 KB |
Output is correct |
24 |
Correct |
13 ms |
15952 KB |
Output is correct |
25 |
Correct |
13 ms |
15952 KB |
Output is correct |
26 |
Correct |
13 ms |
15952 KB |
Output is correct |
27 |
Correct |
14 ms |
16208 KB |
Output is correct |
28 |
Correct |
14 ms |
16208 KB |
Output is correct |
29 |
Correct |
14 ms |
16208 KB |
Output is correct |
30 |
Correct |
14 ms |
16240 KB |
Output is correct |
31 |
Correct |
14 ms |
16208 KB |
Output is correct |
32 |
Correct |
19 ms |
16208 KB |
Output is correct |
33 |
Correct |
14 ms |
16208 KB |
Output is correct |
34 |
Correct |
14 ms |
16208 KB |
Output is correct |
35 |
Correct |
18 ms |
16304 KB |
Output is correct |
36 |
Correct |
14 ms |
16208 KB |
Output is correct |
37 |
Correct |
14 ms |
16208 KB |
Output is correct |
38 |
Correct |
14 ms |
16120 KB |
Output is correct |
39 |
Correct |
14 ms |
16208 KB |
Output is correct |
40 |
Correct |
14 ms |
16376 KB |
Output is correct |
41 |
Correct |
14 ms |
16208 KB |
Output is correct |
42 |
Correct |
14 ms |
16376 KB |
Output is correct |
43 |
Correct |
16 ms |
16220 KB |
Output is correct |
44 |
Correct |
17 ms |
16376 KB |
Output is correct |
45 |
Correct |
19 ms |
16104 KB |
Output is correct |
46 |
Correct |
15 ms |
16208 KB |
Output is correct |
47 |
Correct |
16 ms |
16208 KB |
Output is correct |
48 |
Correct |
16 ms |
16208 KB |
Output is correct |
49 |
Correct |
16 ms |
16292 KB |
Output is correct |
50 |
Correct |
16 ms |
16208 KB |
Output is correct |
51 |
Correct |
16 ms |
16208 KB |
Output is correct |
52 |
Correct |
136 ms |
26384 KB |
Output is correct |
53 |
Correct |
150 ms |
26312 KB |
Output is correct |
54 |
Correct |
143 ms |
26508 KB |
Output is correct |
55 |
Correct |
142 ms |
26300 KB |
Output is correct |
56 |
Correct |
137 ms |
26488 KB |
Output is correct |
57 |
Correct |
136 ms |
26300 KB |
Output is correct |
58 |
Correct |
141 ms |
26296 KB |
Output is correct |
59 |
Correct |
136 ms |
26300 KB |
Output is correct |
60 |
Correct |
130 ms |
26300 KB |
Output is correct |
61 |
Correct |
142 ms |
26296 KB |
Output is correct |
62 |
Correct |
146 ms |
26480 KB |
Output is correct |
63 |
Correct |
137 ms |
26500 KB |
Output is correct |
64 |
Correct |
152 ms |
26492 KB |
Output is correct |
65 |
Correct |
139 ms |
26300 KB |
Output is correct |
66 |
Correct |
141 ms |
26296 KB |
Output is correct |
67 |
Correct |
138 ms |
26488 KB |
Output is correct |
68 |
Correct |
141 ms |
26300 KB |
Output is correct |