#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> edge;
typedef pair<int, ll> pill;
typedef pair<pill, int> data;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
pll l[500000];
int n;
void solve() {
{
int k;
cin >> k;
vector<pll> v;
while(k--) {
ll a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size();) {
int j = i;
while(j < v.size() && v[i].first == v[j].first) {
l[n].second += v[j++].second;
}
l[n++].first = v[(i=j)-1].first;
}
}
ll ret = 0;
for(int i = 0; i < n; i++) {
ll sum = 0;
for(int j = i; j < n; j++) {
sum += l[j].second;
ret = max(ret, sum - (l[j].first - l[i].first));
}
}
cout << ret << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
Compilation message
art.cpp: In function 'void solve()':
art.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size();) {
~~^~~~~~~~~~
art.cpp:31:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[i].first == v[j].first) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
832 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
832 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
848 KB |
Output is correct |
12 |
Correct |
2 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
848 KB |
Output is correct |
14 |
Correct |
2 ms |
880 KB |
Output is correct |
15 |
Correct |
2 ms |
932 KB |
Output is correct |
16 |
Correct |
2 ms |
932 KB |
Output is correct |
17 |
Correct |
3 ms |
932 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
956 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
12 ms |
988 KB |
Output is correct |
22 |
Correct |
2 ms |
996 KB |
Output is correct |
23 |
Correct |
2 ms |
1004 KB |
Output is correct |
24 |
Correct |
2 ms |
1012 KB |
Output is correct |
25 |
Correct |
2 ms |
1036 KB |
Output is correct |
26 |
Correct |
2 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
832 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
848 KB |
Output is correct |
12 |
Correct |
2 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
848 KB |
Output is correct |
14 |
Correct |
2 ms |
880 KB |
Output is correct |
15 |
Correct |
2 ms |
932 KB |
Output is correct |
16 |
Correct |
2 ms |
932 KB |
Output is correct |
17 |
Correct |
3 ms |
932 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
956 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
12 ms |
988 KB |
Output is correct |
22 |
Correct |
2 ms |
996 KB |
Output is correct |
23 |
Correct |
2 ms |
1004 KB |
Output is correct |
24 |
Correct |
2 ms |
1012 KB |
Output is correct |
25 |
Correct |
2 ms |
1036 KB |
Output is correct |
26 |
Correct |
2 ms |
1044 KB |
Output is correct |
27 |
Correct |
22 ms |
1436 KB |
Output is correct |
28 |
Correct |
20 ms |
1564 KB |
Output is correct |
29 |
Correct |
21 ms |
1692 KB |
Output is correct |
30 |
Correct |
48 ms |
1820 KB |
Output is correct |
31 |
Correct |
21 ms |
1948 KB |
Output is correct |
32 |
Correct |
23 ms |
2076 KB |
Output is correct |
33 |
Correct |
22 ms |
2204 KB |
Output is correct |
34 |
Correct |
21 ms |
2336 KB |
Output is correct |
35 |
Correct |
22 ms |
2460 KB |
Output is correct |
36 |
Correct |
20 ms |
2588 KB |
Output is correct |
37 |
Correct |
20 ms |
2716 KB |
Output is correct |
38 |
Correct |
20 ms |
2844 KB |
Output is correct |
39 |
Correct |
22 ms |
2972 KB |
Output is correct |
40 |
Correct |
20 ms |
3100 KB |
Output is correct |
41 |
Correct |
20 ms |
3356 KB |
Output is correct |
42 |
Correct |
21 ms |
3356 KB |
Output is correct |
43 |
Correct |
23 ms |
3484 KB |
Output is correct |
44 |
Correct |
20 ms |
3612 KB |
Output is correct |
45 |
Correct |
21 ms |
3740 KB |
Output is correct |
46 |
Correct |
22 ms |
3868 KB |
Output is correct |
47 |
Correct |
22 ms |
3996 KB |
Output is correct |
48 |
Correct |
20 ms |
4068 KB |
Output is correct |
49 |
Correct |
21 ms |
4272 KB |
Output is correct |
50 |
Correct |
21 ms |
4384 KB |
Output is correct |
51 |
Correct |
21 ms |
4508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
2 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
832 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
832 KB |
Output is correct |
10 |
Correct |
2 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
848 KB |
Output is correct |
12 |
Correct |
2 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
848 KB |
Output is correct |
14 |
Correct |
2 ms |
880 KB |
Output is correct |
15 |
Correct |
2 ms |
932 KB |
Output is correct |
16 |
Correct |
2 ms |
932 KB |
Output is correct |
17 |
Correct |
3 ms |
932 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
956 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
12 ms |
988 KB |
Output is correct |
22 |
Correct |
2 ms |
996 KB |
Output is correct |
23 |
Correct |
2 ms |
1004 KB |
Output is correct |
24 |
Correct |
2 ms |
1012 KB |
Output is correct |
25 |
Correct |
2 ms |
1036 KB |
Output is correct |
26 |
Correct |
2 ms |
1044 KB |
Output is correct |
27 |
Correct |
22 ms |
1436 KB |
Output is correct |
28 |
Correct |
20 ms |
1564 KB |
Output is correct |
29 |
Correct |
21 ms |
1692 KB |
Output is correct |
30 |
Correct |
48 ms |
1820 KB |
Output is correct |
31 |
Correct |
21 ms |
1948 KB |
Output is correct |
32 |
Correct |
23 ms |
2076 KB |
Output is correct |
33 |
Correct |
22 ms |
2204 KB |
Output is correct |
34 |
Correct |
21 ms |
2336 KB |
Output is correct |
35 |
Correct |
22 ms |
2460 KB |
Output is correct |
36 |
Correct |
20 ms |
2588 KB |
Output is correct |
37 |
Correct |
20 ms |
2716 KB |
Output is correct |
38 |
Correct |
20 ms |
2844 KB |
Output is correct |
39 |
Correct |
22 ms |
2972 KB |
Output is correct |
40 |
Correct |
20 ms |
3100 KB |
Output is correct |
41 |
Correct |
20 ms |
3356 KB |
Output is correct |
42 |
Correct |
21 ms |
3356 KB |
Output is correct |
43 |
Correct |
23 ms |
3484 KB |
Output is correct |
44 |
Correct |
20 ms |
3612 KB |
Output is correct |
45 |
Correct |
21 ms |
3740 KB |
Output is correct |
46 |
Correct |
22 ms |
3868 KB |
Output is correct |
47 |
Correct |
22 ms |
3996 KB |
Output is correct |
48 |
Correct |
20 ms |
4068 KB |
Output is correct |
49 |
Correct |
21 ms |
4272 KB |
Output is correct |
50 |
Correct |
21 ms |
4384 KB |
Output is correct |
51 |
Correct |
21 ms |
4508 KB |
Output is correct |
52 |
Execution timed out |
1073 ms |
32532 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |