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>
using namespace std;
#define MAXN 150000
vector<pair<int, int>> con(MAXN), impl(MAXN), luck(MAXN);
vector<vector<int>> skills(MAXN);
vector<bool> unwanted(MAXN);
bool isAcceptable(int a, int b, int c){
if(unwanted.at(a))
return false;
int score = 0;
for(int i = 0; i < 3; ++i){
if(skills.at(a).at(i) >= max(skills.at(b).at(i), skills.at(c).at(i)))
++score;
if(score > 1)
return false;
}
return true;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; ++i){
cin >> con.at(i).first >> impl.at(i).first >> luck.at(i).first;
con.at(i).second = i;
impl.at(i).second = i;
luck.at(i).second = i;
skills.at(i) = {con.at(i).first, impl.at(i).first, luck.at(i).first};
}
//cerr << "jestem1";
sort(con.rbegin(), con.rend());
sort(impl.rbegin(), impl.rend());
sort(luck.rbegin(), luck.rend());
//cerr << "jestem2";
int i = 0, j = 0, k = 0;
bool good = true;
while(i < n || j < n || k < n){
pair<int, int> conI = con.at(i);
pair<int, int> implI = impl.at(j);
pair<int, int> luckI = luck.at(k);
good = true;
if(!isAcceptable(conI.second, implI.second, luckI.second)){
unwanted.at(conI.second) = true;
++i;
good = false;
}
if(!isAcceptable(implI.second, conI.second, luckI.second)){
unwanted.at(implI.second) = true;
++j;
good = false;
}
if(!isAcceptable(luckI.second, implI.second, conI.second)){
unwanted.at(luckI.second) = true;
++k;
good = false;
}
if(good){
cout << conI.first + implI.first + luckI.first;
return 0;
}
}
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... |