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 FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 2e5 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
int n;
int ns[N][3];
bool exist[N];
priority_queue<PII> ks[3];
int main() {
IOS;
cin >> n;
F0R(i, n) {
F0R(j, 3) {
cin >> ns[i][j];
ks[j].push({ns[i][j], i});
}
exist[i] = 1;
}
while(!ks[0].empty() && !ks[1].empty() && !ks[2].empty()) {
bool possible = 1;
F0R(i, 3) {
int id = ks[i].top().S;
F0R(j, 3) if (j != i && ns[id][j] >= ks[j].top().F) {
possible = 0;
exist[id] = 0;
}
}
if (possible) {
cout << ks[0].top().F + ks[1].top().F + ks[2].top().F;
return 0;
}
F0R(i, 3)
while(!ks[i].empty() && !exist[ks[i].top().S]) ks[i].pop();
}
cout << -1;
return 0;
}
# | 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... |