#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 500001 ], b[ 500001 ], p[ 500001 ];
vector <pair<int, int> > v;
set <int> st;
vector <int> vv;
main () {
cin >> n;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ] >> b[ i ];
v.push_back( { a[ i ], b[ i ] } );
}
sort( v.begin(), v.end() );
for ( int i = 0; i < v.size(); i ++ ) {
p[ i + 1 ] = p[ i ] + v[ i ].second;
}
for ( int i = 1; i <= n; i ++ ) {
st.insert( p[ i - 1 ] - v[ i - 1 ].first );
ans = max( ans, ( p[ i ] - v[ i - 1 ].first ) - *st.begin() );
}
cout << ans;
}
/*
(p[ i ] - p[j - 1] ) - (a[i] - a[j])
p[i] - p[j-1] - a[i] + a[j]
p[i] - a[i] - p[j-1] + a[j]
*/
Compilation message
art.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main () {
| ^~~~
art.cpp: In function 'int main()':
art.cpp:58:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for ( int i = 0; i < v.size(); i ++ ) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
844 KB |
Output is correct |
28 |
Correct |
6 ms |
824 KB |
Output is correct |
29 |
Correct |
6 ms |
820 KB |
Output is correct |
30 |
Correct |
6 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
784 KB |
Output is correct |
32 |
Correct |
6 ms |
816 KB |
Output is correct |
33 |
Correct |
6 ms |
828 KB |
Output is correct |
34 |
Correct |
6 ms |
844 KB |
Output is correct |
35 |
Correct |
6 ms |
780 KB |
Output is correct |
36 |
Correct |
6 ms |
816 KB |
Output is correct |
37 |
Correct |
6 ms |
816 KB |
Output is correct |
38 |
Correct |
7 ms |
880 KB |
Output is correct |
39 |
Correct |
6 ms |
816 KB |
Output is correct |
40 |
Correct |
6 ms |
812 KB |
Output is correct |
41 |
Correct |
6 ms |
844 KB |
Output is correct |
42 |
Correct |
6 ms |
792 KB |
Output is correct |
43 |
Correct |
6 ms |
820 KB |
Output is correct |
44 |
Correct |
6 ms |
832 KB |
Output is correct |
45 |
Correct |
7 ms |
844 KB |
Output is correct |
46 |
Correct |
6 ms |
836 KB |
Output is correct |
47 |
Correct |
7 ms |
824 KB |
Output is correct |
48 |
Correct |
7 ms |
860 KB |
Output is correct |
49 |
Correct |
6 ms |
844 KB |
Output is correct |
50 |
Correct |
6 ms |
792 KB |
Output is correct |
51 |
Correct |
6 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
5 ms |
844 KB |
Output is correct |
28 |
Correct |
6 ms |
824 KB |
Output is correct |
29 |
Correct |
6 ms |
820 KB |
Output is correct |
30 |
Correct |
6 ms |
832 KB |
Output is correct |
31 |
Correct |
6 ms |
784 KB |
Output is correct |
32 |
Correct |
6 ms |
816 KB |
Output is correct |
33 |
Correct |
6 ms |
828 KB |
Output is correct |
34 |
Correct |
6 ms |
844 KB |
Output is correct |
35 |
Correct |
6 ms |
780 KB |
Output is correct |
36 |
Correct |
6 ms |
816 KB |
Output is correct |
37 |
Correct |
6 ms |
816 KB |
Output is correct |
38 |
Correct |
7 ms |
880 KB |
Output is correct |
39 |
Correct |
6 ms |
816 KB |
Output is correct |
40 |
Correct |
6 ms |
812 KB |
Output is correct |
41 |
Correct |
6 ms |
844 KB |
Output is correct |
42 |
Correct |
6 ms |
792 KB |
Output is correct |
43 |
Correct |
6 ms |
820 KB |
Output is correct |
44 |
Correct |
6 ms |
832 KB |
Output is correct |
45 |
Correct |
7 ms |
844 KB |
Output is correct |
46 |
Correct |
6 ms |
836 KB |
Output is correct |
47 |
Correct |
7 ms |
824 KB |
Output is correct |
48 |
Correct |
7 ms |
860 KB |
Output is correct |
49 |
Correct |
6 ms |
844 KB |
Output is correct |
50 |
Correct |
6 ms |
792 KB |
Output is correct |
51 |
Correct |
6 ms |
828 KB |
Output is correct |
52 |
Correct |
554 ms |
55912 KB |
Output is correct |
53 |
Correct |
560 ms |
55948 KB |
Output is correct |
54 |
Correct |
561 ms |
55964 KB |
Output is correct |
55 |
Correct |
564 ms |
55968 KB |
Output is correct |
56 |
Correct |
587 ms |
56084 KB |
Output is correct |
57 |
Correct |
591 ms |
55948 KB |
Output is correct |
58 |
Correct |
566 ms |
55884 KB |
Output is correct |
59 |
Correct |
564 ms |
55964 KB |
Output is correct |
60 |
Correct |
563 ms |
55964 KB |
Output is correct |
61 |
Correct |
556 ms |
55852 KB |
Output is correct |
62 |
Correct |
564 ms |
56072 KB |
Output is correct |
63 |
Correct |
570 ms |
55960 KB |
Output is correct |
64 |
Correct |
552 ms |
55912 KB |
Output is correct |
65 |
Correct |
553 ms |
55860 KB |
Output is correct |
66 |
Correct |
554 ms |
55932 KB |
Output is correct |
67 |
Correct |
587 ms |
55968 KB |
Output is correct |
68 |
Correct |
591 ms |
56068 KB |
Output is correct |