#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int x[150002], y[150002], z[150002];
vector<pair<int, int> > xVec, yVec, zVec;
bool deleted[150002];
int maxCnt[150002];
multiset<int> xSet, ySet, zSet;
queue<int> que;
void run(vector<pair<int, int> > &vec, int &pnt, multiset<int> &st){
while(pnt < n && (vec[pnt].first >= *st.rbegin() || deleted[vec[pnt].second])){
if(deleted[vec[pnt].second]){
pnt++;
continue;
}
int x = vec[pnt].second;
maxCnt[x]++;
if(maxCnt[x] == 2) que.push(x);
pnt++;
}
}
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%d %d %d", &x[i], &y[i], &z[i]);
xVec.push_back(make_pair(x[i], i));
yVec.push_back(make_pair(y[i], i));
zVec.push_back(make_pair(z[i], i));
xSet.insert(x[i]);
ySet.insert(y[i]);
zSet.insert(z[i]);
}
sort(xVec.rbegin(), xVec.rend());
sort(yVec.rbegin(), yVec.rend());
sort(zVec.rbegin(), zVec.rend());
int xpnt = 0, ypnt = 0, zpnt = 0;
int sum = 0;
while(1){
run(xVec, xpnt, xSet);
run(yVec, ypnt, ySet);
run(zVec, zpnt, zSet);
while(!que.empty()){
int tmp = que.front(); que.pop();
deleted[tmp] = 1;
xSet.erase(xSet.find(x[tmp]));
ySet.erase(ySet.find(y[tmp]));
zSet.erase(zSet.find(z[tmp]));
}
if(xpnt+ypnt+zpnt == sum) break;
sum = xpnt+ypnt+zpnt;
}
if(xSet.empty()) printf("-1");
else printf("%d", *xSet.rbegin() + *ySet.rbegin() + *zSet.rbegin());
}
Compilation message
team.cpp: In function 'int main()':
team.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
team.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d %d %d", &x[i], &y[i], &z[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |