#include <bits/stdc++.h>
using namespace std;
signed main() {
int n; cin>>n;
vector<pair<long long,long long>>vv(n);
for(auto &z : vv)
cin >> z.first >> z.second;
sort(vv.begin(),vv.end());
vv.push_back({-1,0});
vector<pair<long long,long long>>v;
long long ele = vv[0].first;
long long curr = 0;
for(int i = 0 ; i <= n ; i++) {
if(vv[i].first != ele)
v.push_back({ele,curr}),curr=0,ele=vv[i].first;
curr+=vv[i].second;
}
long long profit = 0;
long long ans = 0;
for(int i = 0 ; i < (int)v.size() ; i++) {
profit+=v[i].second;
if(i > 0) profit-=(v[i].first-v[i-1].first);
profit=max(profit,v[i].second);
ans=max(ans,profit);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
6 ms |
588 KB |
Output is correct |
29 |
Correct |
7 ms |
492 KB |
Output is correct |
30 |
Correct |
7 ms |
588 KB |
Output is correct |
31 |
Correct |
6 ms |
460 KB |
Output is correct |
32 |
Correct |
6 ms |
460 KB |
Output is correct |
33 |
Correct |
6 ms |
460 KB |
Output is correct |
34 |
Correct |
6 ms |
496 KB |
Output is correct |
35 |
Correct |
9 ms |
460 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
37 |
Correct |
6 ms |
588 KB |
Output is correct |
38 |
Correct |
9 ms |
460 KB |
Output is correct |
39 |
Correct |
9 ms |
460 KB |
Output is correct |
40 |
Correct |
6 ms |
460 KB |
Output is correct |
41 |
Correct |
6 ms |
460 KB |
Output is correct |
42 |
Correct |
6 ms |
460 KB |
Output is correct |
43 |
Correct |
6 ms |
588 KB |
Output is correct |
44 |
Correct |
6 ms |
460 KB |
Output is correct |
45 |
Correct |
6 ms |
460 KB |
Output is correct |
46 |
Correct |
6 ms |
460 KB |
Output is correct |
47 |
Correct |
7 ms |
588 KB |
Output is correct |
48 |
Correct |
6 ms |
588 KB |
Output is correct |
49 |
Correct |
6 ms |
496 KB |
Output is correct |
50 |
Correct |
6 ms |
496 KB |
Output is correct |
51 |
Correct |
7 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 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 |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
6 ms |
460 KB |
Output is correct |
28 |
Correct |
6 ms |
588 KB |
Output is correct |
29 |
Correct |
7 ms |
492 KB |
Output is correct |
30 |
Correct |
7 ms |
588 KB |
Output is correct |
31 |
Correct |
6 ms |
460 KB |
Output is correct |
32 |
Correct |
6 ms |
460 KB |
Output is correct |
33 |
Correct |
6 ms |
460 KB |
Output is correct |
34 |
Correct |
6 ms |
496 KB |
Output is correct |
35 |
Correct |
9 ms |
460 KB |
Output is correct |
36 |
Correct |
6 ms |
492 KB |
Output is correct |
37 |
Correct |
6 ms |
588 KB |
Output is correct |
38 |
Correct |
9 ms |
460 KB |
Output is correct |
39 |
Correct |
9 ms |
460 KB |
Output is correct |
40 |
Correct |
6 ms |
460 KB |
Output is correct |
41 |
Correct |
6 ms |
460 KB |
Output is correct |
42 |
Correct |
6 ms |
460 KB |
Output is correct |
43 |
Correct |
6 ms |
588 KB |
Output is correct |
44 |
Correct |
6 ms |
460 KB |
Output is correct |
45 |
Correct |
6 ms |
460 KB |
Output is correct |
46 |
Correct |
6 ms |
460 KB |
Output is correct |
47 |
Correct |
7 ms |
588 KB |
Output is correct |
48 |
Correct |
6 ms |
588 KB |
Output is correct |
49 |
Correct |
6 ms |
496 KB |
Output is correct |
50 |
Correct |
6 ms |
496 KB |
Output is correct |
51 |
Correct |
7 ms |
588 KB |
Output is correct |
52 |
Correct |
627 ms |
24124 KB |
Output is correct |
53 |
Correct |
593 ms |
36760 KB |
Output is correct |
54 |
Correct |
588 ms |
36772 KB |
Output is correct |
55 |
Correct |
593 ms |
36748 KB |
Output is correct |
56 |
Correct |
619 ms |
36796 KB |
Output is correct |
57 |
Correct |
585 ms |
36756 KB |
Output is correct |
58 |
Correct |
619 ms |
36772 KB |
Output is correct |
59 |
Correct |
601 ms |
36756 KB |
Output is correct |
60 |
Correct |
584 ms |
36744 KB |
Output is correct |
61 |
Correct |
599 ms |
36632 KB |
Output is correct |
62 |
Correct |
588 ms |
36760 KB |
Output is correct |
63 |
Correct |
577 ms |
36780 KB |
Output is correct |
64 |
Correct |
606 ms |
36760 KB |
Output is correct |
65 |
Correct |
637 ms |
36768 KB |
Output is correct |
66 |
Correct |
605 ms |
36760 KB |
Output is correct |
67 |
Correct |
612 ms |
36816 KB |
Output is correct |
68 |
Correct |
634 ms |
36760 KB |
Output is correct |