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 <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
multiset<int> V[3];
set<pii> people[3];
int X[N][3];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < 3; j++)
{
cin >> X[i][j];
V[j].insert(X[i][j]);
people[j].insert({X[i][j], i});
}
}
int elim = 0;
while(elim < N)
{
int fail = -1;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(i == j) continue;
int p = people[i].rbegin()->second;
if(X[p][j] == *V[j].rbegin())
fail = p;
}
}
if(fail == -1)
{
int res = 0;
for(int k = 0; k < 3; k++)
res += *V[k].rbegin();
cout << res << '\n';
return 0;
}
else
{
for(int k = 0; k < 3; k++)
{
V[k].erase(V[k].find(X[fail][k]));
people[k].erase({X[fail][k], fail});
}
elim++;
}
}
cout << "-1\n";
}
# | 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... |