#include <bits/stdc++.h>
#define inf 2000000000000000000LL
#define N 500005
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
ll n, resp, sum[N], a, b;
pii v[N];
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1; i <= n; i++) cin>>v[i].f>>v[i].s;
sort(v + 1, v + n + 1);
for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + v[i].s;
ll melhor = -inf;
for(int i = 1; i <= n; i++)
{
melhor = max(melhor, -sum[i - 1] + v[i].f);
resp = max(resp, sum[i] - v[i].f + melhor);
}
cout<<resp<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
1 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
1 ms |
580 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
1 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
1 ms |
580 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
676 KB |
Output is correct |
15 |
Correct |
2 ms |
688 KB |
Output is correct |
16 |
Correct |
2 ms |
712 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
796 KB |
Output is correct |
21 |
Correct |
2 ms |
796 KB |
Output is correct |
22 |
Correct |
2 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
2 ms |
796 KB |
Output is correct |
25 |
Correct |
2 ms |
804 KB |
Output is correct |
26 |
Correct |
1 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
1 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
1 ms |
580 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
676 KB |
Output is correct |
15 |
Correct |
2 ms |
688 KB |
Output is correct |
16 |
Correct |
2 ms |
712 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
796 KB |
Output is correct |
21 |
Correct |
2 ms |
796 KB |
Output is correct |
22 |
Correct |
2 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
2 ms |
796 KB |
Output is correct |
25 |
Correct |
2 ms |
804 KB |
Output is correct |
26 |
Correct |
1 ms |
828 KB |
Output is correct |
27 |
Correct |
3 ms |
1120 KB |
Output is correct |
28 |
Correct |
5 ms |
1236 KB |
Output is correct |
29 |
Correct |
5 ms |
1364 KB |
Output is correct |
30 |
Correct |
3 ms |
1492 KB |
Output is correct |
31 |
Correct |
3 ms |
1620 KB |
Output is correct |
32 |
Correct |
3 ms |
1748 KB |
Output is correct |
33 |
Correct |
3 ms |
1876 KB |
Output is correct |
34 |
Correct |
3 ms |
2004 KB |
Output is correct |
35 |
Correct |
4 ms |
2260 KB |
Output is correct |
36 |
Correct |
3 ms |
2260 KB |
Output is correct |
37 |
Correct |
3 ms |
2388 KB |
Output is correct |
38 |
Correct |
3 ms |
2516 KB |
Output is correct |
39 |
Correct |
3 ms |
2644 KB |
Output is correct |
40 |
Correct |
3 ms |
2772 KB |
Output is correct |
41 |
Correct |
3 ms |
2900 KB |
Output is correct |
42 |
Correct |
3 ms |
2908 KB |
Output is correct |
43 |
Correct |
4 ms |
3152 KB |
Output is correct |
44 |
Correct |
3 ms |
3268 KB |
Output is correct |
45 |
Correct |
4 ms |
3408 KB |
Output is correct |
46 |
Correct |
4 ms |
3524 KB |
Output is correct |
47 |
Correct |
4 ms |
3664 KB |
Output is correct |
48 |
Correct |
3 ms |
3792 KB |
Output is correct |
49 |
Correct |
3 ms |
3920 KB |
Output is correct |
50 |
Correct |
3 ms |
3940 KB |
Output is correct |
51 |
Correct |
4 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
564 KB |
Output is correct |
6 |
Correct |
2 ms |
568 KB |
Output is correct |
7 |
Correct |
1 ms |
572 KB |
Output is correct |
8 |
Correct |
2 ms |
576 KB |
Output is correct |
9 |
Correct |
1 ms |
580 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
676 KB |
Output is correct |
15 |
Correct |
2 ms |
688 KB |
Output is correct |
16 |
Correct |
2 ms |
712 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
796 KB |
Output is correct |
21 |
Correct |
2 ms |
796 KB |
Output is correct |
22 |
Correct |
2 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
2 ms |
796 KB |
Output is correct |
25 |
Correct |
2 ms |
804 KB |
Output is correct |
26 |
Correct |
1 ms |
828 KB |
Output is correct |
27 |
Correct |
3 ms |
1120 KB |
Output is correct |
28 |
Correct |
5 ms |
1236 KB |
Output is correct |
29 |
Correct |
5 ms |
1364 KB |
Output is correct |
30 |
Correct |
3 ms |
1492 KB |
Output is correct |
31 |
Correct |
3 ms |
1620 KB |
Output is correct |
32 |
Correct |
3 ms |
1748 KB |
Output is correct |
33 |
Correct |
3 ms |
1876 KB |
Output is correct |
34 |
Correct |
3 ms |
2004 KB |
Output is correct |
35 |
Correct |
4 ms |
2260 KB |
Output is correct |
36 |
Correct |
3 ms |
2260 KB |
Output is correct |
37 |
Correct |
3 ms |
2388 KB |
Output is correct |
38 |
Correct |
3 ms |
2516 KB |
Output is correct |
39 |
Correct |
3 ms |
2644 KB |
Output is correct |
40 |
Correct |
3 ms |
2772 KB |
Output is correct |
41 |
Correct |
3 ms |
2900 KB |
Output is correct |
42 |
Correct |
3 ms |
2908 KB |
Output is correct |
43 |
Correct |
4 ms |
3152 KB |
Output is correct |
44 |
Correct |
3 ms |
3268 KB |
Output is correct |
45 |
Correct |
4 ms |
3408 KB |
Output is correct |
46 |
Correct |
4 ms |
3524 KB |
Output is correct |
47 |
Correct |
4 ms |
3664 KB |
Output is correct |
48 |
Correct |
3 ms |
3792 KB |
Output is correct |
49 |
Correct |
3 ms |
3920 KB |
Output is correct |
50 |
Correct |
3 ms |
3940 KB |
Output is correct |
51 |
Correct |
4 ms |
4184 KB |
Output is correct |
52 |
Correct |
196 ms |
28496 KB |
Output is correct |
53 |
Correct |
210 ms |
41056 KB |
Output is correct |
54 |
Correct |
218 ms |
53760 KB |
Output is correct |
55 |
Correct |
220 ms |
66436 KB |
Output is correct |
56 |
Correct |
242 ms |
79112 KB |
Output is correct |
57 |
Correct |
194 ms |
91808 KB |
Output is correct |
58 |
Correct |
194 ms |
104460 KB |
Output is correct |
59 |
Correct |
194 ms |
117276 KB |
Output is correct |
60 |
Correct |
191 ms |
129836 KB |
Output is correct |
61 |
Correct |
192 ms |
142236 KB |
Output is correct |
62 |
Correct |
193 ms |
154900 KB |
Output is correct |
63 |
Correct |
190 ms |
167704 KB |
Output is correct |
64 |
Correct |
187 ms |
180260 KB |
Output is correct |
65 |
Correct |
188 ms |
192920 KB |
Output is correct |
66 |
Correct |
198 ms |
205632 KB |
Output is correct |
67 |
Correct |
192 ms |
218300 KB |
Output is correct |
68 |
Correct |
189 ms |
231064 KB |
Output is correct |