/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct beaver
{
int x, y, z, idx;
beaver(int _x = 0, int _y = 0, int _z = 0, int _idx = 0)
{
x = _x;
y = _y;
z = _z;
idx = _idx;
}
};
const int maxn = 150010;
beaver bx[maxn], by[maxn], bz[maxn];
bool cmp_x(beaver b1, beaver b2)
{
return b1.x < b2.x;
}
bool cmp_y(beaver b1, beaver b2)
{
return b1.y < b2.y;
}
bool cmp_z(beaver b1, beaver b2)
{
return b1.z < b2.z;
}
int n, used[maxn];
void solve()
{
cin >> n;
for (int i = 1; i <= n; i ++)
{
beaver b;
cin >> b.x >> b.y >> b.z;
b.idx = i;
bx[i] = by[i] = bz[i] = b;
}
sort(bx + 1, bx + n + 1, cmp_x);
sort(by + 1, by + n + 1, cmp_y);
sort(bz + 1, bz + n + 1, cmp_z);
int px, py, pz;
px = n;
py = n;
pz = n;
for (int i = 1; i <= n; i ++)
{
while(used[bx[px].idx] == 1)
px --;
while(used[by[py].idx] == 1)
py --;
while(used[bz[pz].idx] == 1)
pz --;
int mx = bx[px].x;
int my = by[py].y;
int mz = bz[pz].z;
if (bx[px].y == my || bx[px].z == mz)
{
used[bx[px].idx] = 1;
continue;
}
if (by[py].x == mx || by[py].z == mz)
{
used[by[py].idx] = 1;
continue;
}
if (bz[pz].x == mx || bz[pz].x == mx)
{
used[bz[pz].idx] = 1;
continue;
}
cout << mx + my + mz << endl;
return;
}
cout << -1 << endl;
}
int main()
{
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7356 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7252 KB |
Output is correct |
11 |
Correct |
3 ms |
7252 KB |
Output is correct |
12 |
Correct |
3 ms |
7252 KB |
Output is correct |
13 |
Correct |
3 ms |
7280 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7356 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7252 KB |
Output is correct |
11 |
Correct |
3 ms |
7252 KB |
Output is correct |
12 |
Correct |
3 ms |
7252 KB |
Output is correct |
13 |
Correct |
3 ms |
7280 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7272 KB |
Output is correct |
2 |
Correct |
3 ms |
7360 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7280 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7356 KB |
Output is correct |
8 |
Correct |
5 ms |
7352 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7356 KB |
Output is correct |
11 |
Correct |
66 ms |
8212 KB |
Output is correct |
12 |
Incorrect |
46 ms |
8252 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7272 KB |
Output is correct |
2 |
Correct |
3 ms |
7360 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7280 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7356 KB |
Output is correct |
8 |
Correct |
5 ms |
7352 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7356 KB |
Output is correct |
11 |
Correct |
66 ms |
8212 KB |
Output is correct |
12 |
Incorrect |
46 ms |
8252 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7272 KB |
Output is correct |
2 |
Correct |
3 ms |
7360 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7280 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7356 KB |
Output is correct |
8 |
Correct |
5 ms |
7352 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7356 KB |
Output is correct |
11 |
Correct |
66 ms |
8212 KB |
Output is correct |
12 |
Incorrect |
46 ms |
8252 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7272 KB |
Output is correct |
2 |
Correct |
3 ms |
7360 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7280 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7356 KB |
Output is correct |
8 |
Correct |
5 ms |
7352 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7356 KB |
Output is correct |
11 |
Correct |
66 ms |
8212 KB |
Output is correct |
12 |
Incorrect |
46 ms |
8252 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7356 KB |
Output is correct |
3 |
Correct |
3 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7356 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7252 KB |
Output is correct |
10 |
Correct |
3 ms |
7252 KB |
Output is correct |
11 |
Correct |
3 ms |
7252 KB |
Output is correct |
12 |
Correct |
3 ms |
7252 KB |
Output is correct |
13 |
Correct |
3 ms |
7280 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |