#include <bits/stdc++.h>
using namespace std;
int n;
struct spot {
int x, y, w;
};
vector<spot> v;
long long solve(auto comp) {
sort(v.begin(), v.end(), comp);
vector<long long> sa;
sa.push_back((long long) v[0].w);
int curIdx = 0;
for (int i = 1; i < n; i++) {
if (!comp(v[i - 1], v[i])) sa[curIdx] += (long long) v[i].w;
else sa.push_back((long long) v[i].w), curIdx++;
}
long long ans = -1e18;
long long cur = 0ll;
for (auto &tmp : sa) {
cur += tmp;
ans = max(ans, cur);
cur = max(cur, 0ll);
cout << tmp << ' ';
}
cout << '\n';
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
int x, y, w;
cin >> x >> y >> w;
v.push_back({x, y, w});
}
cout << max(solve([](const spot& a, const spot& b) { return a.x < b.x; }), solve([](const spot& a, const spot& b) { return a.y < b.y; })) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |