#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 500100;
map<ll, ll> sum;
vector<pair<ll, ll> > values;
vector<ll> pref;
ll n, x, y;
ll get_val(int l, int r) {
ll sum =1LL* pref[r] - pref[l-1];
ll diff = values[r].first - values[l].first;
return sum - diff;
}
vector<pair<ll,ll> > temp;
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);
cin>>n;
values.pb(mp(0,0));
for(int i=0;i<n;i++) {
cin>>x>>y;
values.pb(mp(x,y));
}
sort(values.begin(), values.end());
pref.pb(0LL);
for(int i=1;i<values.size();i++) {
pref.pb(pref.back() + values[i].second);
}
ll l = 1LL;
ll result = get_val(1,1);
ll max_pref = values[1].first;
for(ll i=2;i<values.size();i++) {
max_pref = max(max_pref, values[i].first - pref[i-1]);
ll curr_val = pref[i] - values[i].first + max_pref;
result = max(result, curr_val);
}
cout<<result;
return 0;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<values.size();i++) {
~^~~~~~~~~~~~~~
art.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=2;i<values.size();i++) {
~^~~~~~~~~~~~~~
art.cpp:36:8: warning: unused variable 'l' [-Wunused-variable]
ll l = 1LL;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
540 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
540 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
12 |
Correct |
3 ms |
628 KB |
Output is correct |
13 |
Correct |
3 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
4 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
4 ms |
796 KB |
Output is correct |
20 |
Correct |
3 ms |
796 KB |
Output is correct |
21 |
Correct |
4 ms |
824 KB |
Output is correct |
22 |
Correct |
3 ms |
824 KB |
Output is correct |
23 |
Correct |
4 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
824 KB |
Output is correct |
25 |
Correct |
3 ms |
824 KB |
Output is correct |
26 |
Correct |
4 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
540 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
12 |
Correct |
3 ms |
628 KB |
Output is correct |
13 |
Correct |
3 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
4 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
4 ms |
796 KB |
Output is correct |
20 |
Correct |
3 ms |
796 KB |
Output is correct |
21 |
Correct |
4 ms |
824 KB |
Output is correct |
22 |
Correct |
3 ms |
824 KB |
Output is correct |
23 |
Correct |
4 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
824 KB |
Output is correct |
25 |
Correct |
3 ms |
824 KB |
Output is correct |
26 |
Correct |
4 ms |
824 KB |
Output is correct |
27 |
Correct |
11 ms |
1156 KB |
Output is correct |
28 |
Correct |
10 ms |
1156 KB |
Output is correct |
29 |
Correct |
11 ms |
1284 KB |
Output is correct |
30 |
Correct |
9 ms |
1412 KB |
Output is correct |
31 |
Correct |
11 ms |
1540 KB |
Output is correct |
32 |
Correct |
11 ms |
1796 KB |
Output is correct |
33 |
Correct |
9 ms |
1924 KB |
Output is correct |
34 |
Correct |
10 ms |
1940 KB |
Output is correct |
35 |
Correct |
15 ms |
2068 KB |
Output is correct |
36 |
Correct |
10 ms |
2196 KB |
Output is correct |
37 |
Correct |
9 ms |
2372 KB |
Output is correct |
38 |
Correct |
12 ms |
2372 KB |
Output is correct |
39 |
Correct |
11 ms |
2372 KB |
Output is correct |
40 |
Correct |
10 ms |
2372 KB |
Output is correct |
41 |
Correct |
9 ms |
2432 KB |
Output is correct |
42 |
Correct |
9 ms |
2432 KB |
Output is correct |
43 |
Correct |
9 ms |
2432 KB |
Output is correct |
44 |
Correct |
10 ms |
2432 KB |
Output is correct |
45 |
Correct |
11 ms |
2432 KB |
Output is correct |
46 |
Correct |
9 ms |
2432 KB |
Output is correct |
47 |
Correct |
10 ms |
2432 KB |
Output is correct |
48 |
Correct |
12 ms |
2432 KB |
Output is correct |
49 |
Correct |
10 ms |
2432 KB |
Output is correct |
50 |
Correct |
9 ms |
2432 KB |
Output is correct |
51 |
Correct |
10 ms |
2432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
540 KB |
Output is correct |
4 |
Correct |
3 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
3 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
624 KB |
Output is correct |
12 |
Correct |
3 ms |
628 KB |
Output is correct |
13 |
Correct |
3 ms |
640 KB |
Output is correct |
14 |
Correct |
2 ms |
660 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
4 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
4 ms |
796 KB |
Output is correct |
20 |
Correct |
3 ms |
796 KB |
Output is correct |
21 |
Correct |
4 ms |
824 KB |
Output is correct |
22 |
Correct |
3 ms |
824 KB |
Output is correct |
23 |
Correct |
4 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
824 KB |
Output is correct |
25 |
Correct |
3 ms |
824 KB |
Output is correct |
26 |
Correct |
4 ms |
824 KB |
Output is correct |
27 |
Correct |
11 ms |
1156 KB |
Output is correct |
28 |
Correct |
10 ms |
1156 KB |
Output is correct |
29 |
Correct |
11 ms |
1284 KB |
Output is correct |
30 |
Correct |
9 ms |
1412 KB |
Output is correct |
31 |
Correct |
11 ms |
1540 KB |
Output is correct |
32 |
Correct |
11 ms |
1796 KB |
Output is correct |
33 |
Correct |
9 ms |
1924 KB |
Output is correct |
34 |
Correct |
10 ms |
1940 KB |
Output is correct |
35 |
Correct |
15 ms |
2068 KB |
Output is correct |
36 |
Correct |
10 ms |
2196 KB |
Output is correct |
37 |
Correct |
9 ms |
2372 KB |
Output is correct |
38 |
Correct |
12 ms |
2372 KB |
Output is correct |
39 |
Correct |
11 ms |
2372 KB |
Output is correct |
40 |
Correct |
10 ms |
2372 KB |
Output is correct |
41 |
Correct |
9 ms |
2432 KB |
Output is correct |
42 |
Correct |
9 ms |
2432 KB |
Output is correct |
43 |
Correct |
9 ms |
2432 KB |
Output is correct |
44 |
Correct |
10 ms |
2432 KB |
Output is correct |
45 |
Correct |
11 ms |
2432 KB |
Output is correct |
46 |
Correct |
9 ms |
2432 KB |
Output is correct |
47 |
Correct |
10 ms |
2432 KB |
Output is correct |
48 |
Correct |
12 ms |
2432 KB |
Output is correct |
49 |
Correct |
10 ms |
2432 KB |
Output is correct |
50 |
Correct |
9 ms |
2432 KB |
Output is correct |
51 |
Correct |
10 ms |
2432 KB |
Output is correct |
52 |
Correct |
883 ms |
19808 KB |
Output is correct |
53 |
Correct |
816 ms |
21516 KB |
Output is correct |
54 |
Correct |
775 ms |
21564 KB |
Output is correct |
55 |
Correct |
767 ms |
21748 KB |
Output is correct |
56 |
Correct |
730 ms |
21748 KB |
Output is correct |
57 |
Correct |
734 ms |
21748 KB |
Output is correct |
58 |
Correct |
758 ms |
21748 KB |
Output is correct |
59 |
Correct |
748 ms |
21748 KB |
Output is correct |
60 |
Correct |
773 ms |
21748 KB |
Output is correct |
61 |
Correct |
744 ms |
21748 KB |
Output is correct |
62 |
Correct |
753 ms |
21748 KB |
Output is correct |
63 |
Correct |
861 ms |
21748 KB |
Output is correct |
64 |
Correct |
795 ms |
21748 KB |
Output is correct |
65 |
Correct |
775 ms |
21748 KB |
Output is correct |
66 |
Correct |
788 ms |
21748 KB |
Output is correct |
67 |
Correct |
732 ms |
21748 KB |
Output is correct |
68 |
Correct |
761 ms |
21748 KB |
Output is correct |