#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, wiel, wart, l = 0, p = 0, overall = 0;
cin >> n;
map<long long, long long> m;
vector<vector<long long>> v;
for (int i = 0; i < n; i++) {
cin >> wiel >> wart;
m[wiel] += wart;
overall += wart;
}
for (auto [wie, war] : m) {
v.push_back({wie, war});
}
long long wyn = 0, suma = v[0][1], osw = v[v.size() - 1][0], i = 0;
while (l < v.size()) {
if (i < v.size()) {
if (overall - osw + v[i][0] > wyn) {
wyn = overall - osw + v[i][0];
}
if (v[i][1] > wyn) {
wyn = v[i][1];
}
overall -= v[i][1];
}
i += 1;
if ((l >= p) || (p < v.size() && suma - v[p][0] + v[l][0] > v[p][1])) {
if (suma - v[p][0] + v[l][0] > wyn) {
wyn = suma - v[p][0] + v[l][0];
}
p += 1;
if (p < v.size() - 1) {
suma += v[p][1];
}
}
else {
suma -= v[l][1];
l += 1;
}
}
cout << wyn;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:19:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while (l < v.size()) {
| ~~^~~~~~~~~~
art.cpp:20:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (i < v.size()) {
| ~~^~~~~~~~~~
art.cpp:30:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if ((l >= p) || (p < v.size() && suma - v[p][0] + v[l][0] > v[p][1])) {
| ~~^~~~~~~~~~
art.cpp:35:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (p < v.size() - 1) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
4 ms |
1104 KB |
Output is correct |
28 |
Correct |
3 ms |
1104 KB |
Output is correct |
29 |
Correct |
3 ms |
996 KB |
Output is correct |
30 |
Correct |
3 ms |
1104 KB |
Output is correct |
31 |
Correct |
3 ms |
1104 KB |
Output is correct |
32 |
Correct |
3 ms |
1104 KB |
Output is correct |
33 |
Correct |
3 ms |
1104 KB |
Output is correct |
34 |
Correct |
3 ms |
1116 KB |
Output is correct |
35 |
Correct |
3 ms |
1104 KB |
Output is correct |
36 |
Correct |
3 ms |
1104 KB |
Output is correct |
37 |
Correct |
4 ms |
1104 KB |
Output is correct |
38 |
Correct |
3 ms |
1104 KB |
Output is correct |
39 |
Correct |
3 ms |
1104 KB |
Output is correct |
40 |
Correct |
3 ms |
1104 KB |
Output is correct |
41 |
Correct |
3 ms |
1104 KB |
Output is correct |
42 |
Correct |
3 ms |
1104 KB |
Output is correct |
43 |
Correct |
3 ms |
1104 KB |
Output is correct |
44 |
Correct |
3 ms |
1008 KB |
Output is correct |
45 |
Correct |
3 ms |
1104 KB |
Output is correct |
46 |
Correct |
3 ms |
1104 KB |
Output is correct |
47 |
Correct |
3 ms |
1104 KB |
Output is correct |
48 |
Correct |
3 ms |
1104 KB |
Output is correct |
49 |
Correct |
3 ms |
1104 KB |
Output is correct |
50 |
Correct |
3 ms |
1024 KB |
Output is correct |
51 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
504 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
508 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
4 ms |
1104 KB |
Output is correct |
28 |
Correct |
3 ms |
1104 KB |
Output is correct |
29 |
Correct |
3 ms |
996 KB |
Output is correct |
30 |
Correct |
3 ms |
1104 KB |
Output is correct |
31 |
Correct |
3 ms |
1104 KB |
Output is correct |
32 |
Correct |
3 ms |
1104 KB |
Output is correct |
33 |
Correct |
3 ms |
1104 KB |
Output is correct |
34 |
Correct |
3 ms |
1116 KB |
Output is correct |
35 |
Correct |
3 ms |
1104 KB |
Output is correct |
36 |
Correct |
3 ms |
1104 KB |
Output is correct |
37 |
Correct |
4 ms |
1104 KB |
Output is correct |
38 |
Correct |
3 ms |
1104 KB |
Output is correct |
39 |
Correct |
3 ms |
1104 KB |
Output is correct |
40 |
Correct |
3 ms |
1104 KB |
Output is correct |
41 |
Correct |
3 ms |
1104 KB |
Output is correct |
42 |
Correct |
3 ms |
1104 KB |
Output is correct |
43 |
Correct |
3 ms |
1104 KB |
Output is correct |
44 |
Correct |
3 ms |
1008 KB |
Output is correct |
45 |
Correct |
3 ms |
1104 KB |
Output is correct |
46 |
Correct |
3 ms |
1104 KB |
Output is correct |
47 |
Correct |
3 ms |
1104 KB |
Output is correct |
48 |
Correct |
3 ms |
1104 KB |
Output is correct |
49 |
Correct |
3 ms |
1104 KB |
Output is correct |
50 |
Correct |
3 ms |
1024 KB |
Output is correct |
51 |
Correct |
3 ms |
1116 KB |
Output is correct |
52 |
Correct |
482 ms |
60392 KB |
Output is correct |
53 |
Correct |
450 ms |
66184 KB |
Output is correct |
54 |
Correct |
509 ms |
66468 KB |
Output is correct |
55 |
Correct |
595 ms |
66268 KB |
Output is correct |
56 |
Correct |
509 ms |
66136 KB |
Output is correct |
57 |
Correct |
514 ms |
66220 KB |
Output is correct |
58 |
Correct |
553 ms |
66276 KB |
Output is correct |
59 |
Correct |
501 ms |
66228 KB |
Output is correct |
60 |
Correct |
566 ms |
66032 KB |
Output is correct |
61 |
Correct |
607 ms |
65964 KB |
Output is correct |
62 |
Correct |
522 ms |
66144 KB |
Output is correct |
63 |
Correct |
501 ms |
62940 KB |
Output is correct |
64 |
Correct |
501 ms |
66156 KB |
Output is correct |
65 |
Correct |
484 ms |
66152 KB |
Output is correct |
66 |
Correct |
472 ms |
66304 KB |
Output is correct |
67 |
Correct |
460 ms |
64960 KB |
Output is correct |
68 |
Correct |
509 ms |
59548 KB |
Output is correct |