#include <bits/stdc++.h>
using namespace std;
vector<int> posx, posy;
int compress(int x, bool X) {
if (X) return lower_bound(begin(posx), end(posx), x) - begin(posx);
return lower_bound(begin(posy), end(posy), x) - begin(posy);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q;
cin >> q;
vector<vector<int>> info;
vector<int> prefx(q), prefy(q);
while (q--) {
int x, y, v;
cin >> x >> y >> v;
posx.push_back(x);
posy.push_back(y);
info.push_back({x, y, v});
}
sort(begin(posx), end(posx));
sort(begin(posy), end(posy));
posx.erase(unique(begin(posx), end(posx)), end(posx));
posy.erase(unique(begin(posy), end(posy)), end(posy));
for (auto& i : info) {
prefx[compress(i[0], true)] += i[2];
prefy[compress(i[1], false)] += i[2];
}
int sm = 0, mn = 0, ans = 0;
for (int i = 0; i < posx.size(); i++) {
sm += prefx[i];
mn = min(mn, sm);
ans = max(ans, sm - mn);
}
sm = 0, mn = 0;
for (int i = 0; i < posy.size(); i++) {
sm += prefy[i];
mn = min(mn, sm);
ans = max(ans, sm - mn);
}
cout << ans;
}
Compilation message
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < posx.size(); i++) {
| ~~^~~~~~~~~~~~~
bulldozer.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < posy.size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |