/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
using namespace std;
template<class T1, class T2> inline int chkmin(T1 &x, const T2 &y) {
if (x > y) {
x = y;
return 1;
}
else {
return 0;
}
}
template<class T1, class T2> inline int chkmax(T1 &x, const T2 &y) {
if (x < y) {
x = y;
return 1;
}
else {
return 0;
}
}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
template<class iterator> void output(iterator begin, iterator end, ostream &out = cerr) {
while (begin != end) {
out << (*begin) << " ";
begin++;
}
out << endl;
}
template<class T> void output(const T &x, ostream &out = cerr) {
output(x.begin(), x.end(), out);
}
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int MAXN = 500228;
int n;
long long a[MAXN], b[MAXN];
int main() {
fast_io();
//read("input");
cin >> n;
vector<pair<long long, int> > st;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
st.pb({a[i], i});
}
sort(all(st));
long long sum = 0;
long long ans = -1e18;
long long kek = -1e18;
for (int i = 0; i < n; i++) {
chkmax(kek, st[i].first - sum);
// cout << b[st[i].second] << endl;
chkmax(ans, sum + b[st[i].second] - st[i].first + kek);
sum += b[st[i].second];
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
436 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
436 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
4 ms |
768 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
4 ms |
768 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
4 ms |
768 KB |
Output is correct |
34 |
Correct |
6 ms |
768 KB |
Output is correct |
35 |
Correct |
4 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
4 ms |
768 KB |
Output is correct |
40 |
Correct |
4 ms |
768 KB |
Output is correct |
41 |
Correct |
4 ms |
768 KB |
Output is correct |
42 |
Correct |
4 ms |
768 KB |
Output is correct |
43 |
Correct |
4 ms |
768 KB |
Output is correct |
44 |
Correct |
4 ms |
768 KB |
Output is correct |
45 |
Correct |
4 ms |
768 KB |
Output is correct |
46 |
Correct |
4 ms |
768 KB |
Output is correct |
47 |
Correct |
4 ms |
768 KB |
Output is correct |
48 |
Correct |
4 ms |
768 KB |
Output is correct |
49 |
Correct |
4 ms |
768 KB |
Output is correct |
50 |
Correct |
4 ms |
768 KB |
Output is correct |
51 |
Correct |
4 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
436 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
768 KB |
Output is correct |
28 |
Correct |
4 ms |
768 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
4 ms |
768 KB |
Output is correct |
31 |
Correct |
4 ms |
768 KB |
Output is correct |
32 |
Correct |
4 ms |
768 KB |
Output is correct |
33 |
Correct |
4 ms |
768 KB |
Output is correct |
34 |
Correct |
6 ms |
768 KB |
Output is correct |
35 |
Correct |
4 ms |
768 KB |
Output is correct |
36 |
Correct |
4 ms |
768 KB |
Output is correct |
37 |
Correct |
4 ms |
768 KB |
Output is correct |
38 |
Correct |
4 ms |
768 KB |
Output is correct |
39 |
Correct |
4 ms |
768 KB |
Output is correct |
40 |
Correct |
4 ms |
768 KB |
Output is correct |
41 |
Correct |
4 ms |
768 KB |
Output is correct |
42 |
Correct |
4 ms |
768 KB |
Output is correct |
43 |
Correct |
4 ms |
768 KB |
Output is correct |
44 |
Correct |
4 ms |
768 KB |
Output is correct |
45 |
Correct |
4 ms |
768 KB |
Output is correct |
46 |
Correct |
4 ms |
768 KB |
Output is correct |
47 |
Correct |
4 ms |
768 KB |
Output is correct |
48 |
Correct |
4 ms |
768 KB |
Output is correct |
49 |
Correct |
4 ms |
768 KB |
Output is correct |
50 |
Correct |
4 ms |
768 KB |
Output is correct |
51 |
Correct |
4 ms |
768 KB |
Output is correct |
52 |
Correct |
212 ms |
28756 KB |
Output is correct |
53 |
Correct |
211 ms |
28876 KB |
Output is correct |
54 |
Correct |
210 ms |
28884 KB |
Output is correct |
55 |
Correct |
216 ms |
28892 KB |
Output is correct |
56 |
Correct |
219 ms |
28924 KB |
Output is correct |
57 |
Correct |
222 ms |
28884 KB |
Output is correct |
58 |
Correct |
219 ms |
28888 KB |
Output is correct |
59 |
Correct |
238 ms |
28884 KB |
Output is correct |
60 |
Correct |
212 ms |
28904 KB |
Output is correct |
61 |
Correct |
245 ms |
28756 KB |
Output is correct |
62 |
Correct |
244 ms |
28904 KB |
Output is correct |
63 |
Correct |
223 ms |
28884 KB |
Output is correct |
64 |
Correct |
297 ms |
29012 KB |
Output is correct |
65 |
Correct |
214 ms |
28756 KB |
Output is correct |
66 |
Correct |
218 ms |
28916 KB |
Output is correct |
67 |
Correct |
249 ms |
28820 KB |
Output is correct |
68 |
Correct |
229 ms |
28884 KB |
Output is correct |