#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
//your code goes here
int n;
cin >> n;
vector <vector <int>> arr = {};
vector <vector <int>> arr2 = {};
for(int i = 0; i < n; i++) {
int x, y, z;
cin >> x >> y >> z;
arr.push_back({x, y, z});
arr2.push_back({y, z, i});
}
multiset <int> mult = {};
for(int i = 0; i < n; i++) {
mult.insert(arr2[i][1]);
}
sort(arr2.begin(), arr2.end(), [&](auto& left, auto& right) {
return left[0] > right[0];
});
int cur = 0;
int total = -1e18;
for(int i = 0; i < n; i++) {
cur = max(cur, i);
int a = arr2[i][0];
int b = arr2[i][1];
int c = arr2[i][2];
// cout << i << " v " << endl;
for(int i = cur; i < n; i++) {
if(arr2[cur][0] != a) {
break;
}
auto it = mult.find(arr2[cur][1]);
mult.erase(it);
cur++;
}
auto it = mult.end();
int v = 0;
if(mult.size() != 0) {
it--;
v = *it;
}
if(v <= b) {
arr[c].push_back(-1e18);
continue;
}
arr[c].push_back(v+a);
}
// cout << "HELLO" << endl;
for(int i = 0; i < n; i++) {
int v = arr[i][3];
mult.insert(v);
}
sort(arr.begin(), arr.end(), [&](auto& left, auto& right) {
return left[0] > right[0];
});
cur = 0;
for(int i = 0; i < n; i++) {
cur = max(cur, i);
int a = arr[i][0];
int b = arr[i][1];
int c = arr[i][2];
int d = arr[i][3];
for(int i = cur; i < n; i++) {
if(arr[cur][0] != a) {
break;
}
auto it = mult.find(arr[cur][3]);
mult.erase(it);
cur++;
}
auto it = mult.end();
int v = -1e18;
if(mult.size() != 0) {
it--;
v = *it;
}
if(v == -1e18) {
continue;
}
int v2 = v+a;
// cout << i << " " << v2 << " " << v << " " << a << " " << b << " " << c << " " << d << endl;
total = max(total, v2);
}
if(total == -1e18) {
cout << -1 << endl;
} else {
cout << total << endl;
}
return 0;
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:66:13: warning: unused variable 'b' [-Wunused-variable]
66 | int b = arr[i][1];
| ^
team.cpp:67:13: warning: unused variable 'c' [-Wunused-variable]
67 | int c = arr[i][2];
| ^
team.cpp:68:13: warning: unused variable 'd' [-Wunused-variable]
68 | int d = arr[i][3];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
169 ms |
34000 KB |
Output is correct |
12 |
Incorrect |
101 ms |
22960 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
169 ms |
34000 KB |
Output is correct |
12 |
Incorrect |
101 ms |
22960 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
169 ms |
34000 KB |
Output is correct |
12 |
Incorrect |
101 ms |
22960 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
169 ms |
34000 KB |
Output is correct |
12 |
Incorrect |
101 ms |
22960 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |