#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define sz(a) (long long) a.size()
#define endl '\n'
const long long INF = 1e18, MOD = 1e9+7;
void test_case() {
int n;
cin >> n;
vector<int> a;
map<int,int> mp;
for (int i = 0; i < n; i++) {
int s, v;
cin >> s >> v;
if (!mp.count(s)) {
a.push_back(s);
}
mp[s] += v;
}
sort(a.begin(), a.end());
set<pair<int,int>> s;
vector<int> value(sz(a));
int cur = 0;
for (int i = 0; i < sz(a); i++) {
cur += mp[a[i]];
s.insert({cur - a[i], i});
value[i] = cur - a[i];
}
int ans = 0;
for (int i = 0; i < sz(a); i++) {
ans = max(ans, (*s.rbegin()).fi + a[i] - (i? value[i - 1] + a[i - 1] : 0));
auto it = s.find({value[i], i});
assert(it != s.end());
s.erase(it);
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
test_case();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
1108 KB |
Output is correct |
28 |
Correct |
4 ms |
1096 KB |
Output is correct |
29 |
Correct |
5 ms |
1096 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
7 ms |
1108 KB |
Output is correct |
32 |
Correct |
5 ms |
1108 KB |
Output is correct |
33 |
Correct |
5 ms |
1108 KB |
Output is correct |
34 |
Correct |
5 ms |
1108 KB |
Output is correct |
35 |
Correct |
5 ms |
1096 KB |
Output is correct |
36 |
Correct |
8 ms |
1112 KB |
Output is correct |
37 |
Correct |
5 ms |
1096 KB |
Output is correct |
38 |
Correct |
6 ms |
1108 KB |
Output is correct |
39 |
Correct |
7 ms |
1108 KB |
Output is correct |
40 |
Correct |
6 ms |
1108 KB |
Output is correct |
41 |
Correct |
5 ms |
1108 KB |
Output is correct |
42 |
Correct |
5 ms |
1096 KB |
Output is correct |
43 |
Correct |
5 ms |
1104 KB |
Output is correct |
44 |
Correct |
5 ms |
1108 KB |
Output is correct |
45 |
Correct |
5 ms |
1096 KB |
Output is correct |
46 |
Correct |
5 ms |
1108 KB |
Output is correct |
47 |
Correct |
5 ms |
1108 KB |
Output is correct |
48 |
Correct |
5 ms |
1108 KB |
Output is correct |
49 |
Correct |
5 ms |
1104 KB |
Output is correct |
50 |
Correct |
6 ms |
1100 KB |
Output is correct |
51 |
Correct |
7 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
1108 KB |
Output is correct |
28 |
Correct |
4 ms |
1096 KB |
Output is correct |
29 |
Correct |
5 ms |
1096 KB |
Output is correct |
30 |
Correct |
6 ms |
1108 KB |
Output is correct |
31 |
Correct |
7 ms |
1108 KB |
Output is correct |
32 |
Correct |
5 ms |
1108 KB |
Output is correct |
33 |
Correct |
5 ms |
1108 KB |
Output is correct |
34 |
Correct |
5 ms |
1108 KB |
Output is correct |
35 |
Correct |
5 ms |
1096 KB |
Output is correct |
36 |
Correct |
8 ms |
1112 KB |
Output is correct |
37 |
Correct |
5 ms |
1096 KB |
Output is correct |
38 |
Correct |
6 ms |
1108 KB |
Output is correct |
39 |
Correct |
7 ms |
1108 KB |
Output is correct |
40 |
Correct |
6 ms |
1108 KB |
Output is correct |
41 |
Correct |
5 ms |
1108 KB |
Output is correct |
42 |
Correct |
5 ms |
1096 KB |
Output is correct |
43 |
Correct |
5 ms |
1104 KB |
Output is correct |
44 |
Correct |
5 ms |
1108 KB |
Output is correct |
45 |
Correct |
5 ms |
1096 KB |
Output is correct |
46 |
Correct |
5 ms |
1108 KB |
Output is correct |
47 |
Correct |
5 ms |
1108 KB |
Output is correct |
48 |
Correct |
5 ms |
1108 KB |
Output is correct |
49 |
Correct |
5 ms |
1104 KB |
Output is correct |
50 |
Correct |
6 ms |
1100 KB |
Output is correct |
51 |
Correct |
7 ms |
1108 KB |
Output is correct |
52 |
Correct |
764 ms |
73200 KB |
Output is correct |
53 |
Correct |
817 ms |
73156 KB |
Output is correct |
54 |
Correct |
843 ms |
73208 KB |
Output is correct |
55 |
Correct |
812 ms |
73276 KB |
Output is correct |
56 |
Correct |
912 ms |
73164 KB |
Output is correct |
57 |
Correct |
916 ms |
73160 KB |
Output is correct |
58 |
Correct |
902 ms |
73096 KB |
Output is correct |
59 |
Correct |
869 ms |
73160 KB |
Output is correct |
60 |
Correct |
834 ms |
73220 KB |
Output is correct |
61 |
Correct |
835 ms |
73256 KB |
Output is correct |
62 |
Correct |
822 ms |
73216 KB |
Output is correct |
63 |
Correct |
825 ms |
73164 KB |
Output is correct |
64 |
Correct |
797 ms |
73188 KB |
Output is correct |
65 |
Correct |
787 ms |
73140 KB |
Output is correct |
66 |
Correct |
772 ms |
73096 KB |
Output is correct |
67 |
Correct |
762 ms |
73180 KB |
Output is correct |
68 |
Correct |
857 ms |
73288 KB |
Output is correct |