This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define task "A"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 1e5 + 5;
const ll INF = 1e18 + 5;
int x[MAXN], y[MAXN], z[MAXN], a[MAXN], b[MAXN], c[MAXN];
int n;
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> y[i] >> z[i];
a[i] = b[i] = c[i] = i;
}
}
void Solve()
{
sort(a + 1, a + n + 1, [](int i, int j)
{
return x[i] < x[j];
});
sort(b + 1, b + n + 1, [](int i, int j)
{
return y[i] < y[j];
});
sort(c + 1, c + n + 1, [](int i, int j)
{
return z[i] < z[j];
});
int i = n, j = n, t = n;
while (i >= 1 && j >= 1 && t >= 1)
{
//cout << i << ' ' << j << ' ' << t << '\n';
if (x[a[i]] <= x[b[j]])
{
j--;
continue;
}
if (x[a[i]] <= x[c[t]])
{
t--;
continue;
}
if (y[b[j]] <= y[a[i]])
{
i--;
continue;
}
if (y[b[j]] <= y[c[t]])
{
t--;
continue;
}
if (z[c[t]] <= z[a[i]])
{
i--;
continue;
}
if (z[c[t]] <= z[b[j]])
{
j--;
continue;
}
cout << x[a[i]] + y[b[j]] + z[c[t]];
return;
}
cout << -1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
Compilation message (stderr)
team.cpp: In function 'int main()':
team.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |