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>
typedef long long ll;
using namespace std;
const ll MAX_N = 1e5 + 10;
ll n;
pair<ll, ll> a[MAX_N], b[MAX_N], c[MAX_N];
pair<ll, pair<ll, ll> > p[MAX_N];
signed main() {
cin >> n;
for(ll i = 0; i < n; i ++) {
cin >> p[i].first >> p[i].second.first >> p[i].second.second;
a[i] = {p[i].first, i};
b[i] = {p[i].second.first, i};
c[i] = {p[i].second.second, i};
}
sort(a, a + n);
sort(b, b + n);
sort(c, c + n);
ll pa = n - 1, pb = n - 1, pc = n - 1;
ll ans = -1;
set<ll> st;
while(true) {
if(st.find(a[pa].second) != st.end()) { pa --; continue; }
if(st.find(b[pb].second) != st.end()) { pb --; continue; }
if(st.find(c[pc].second) != st.end()) { pc --; continue; }
if(a[pa].second == b[pb].second || a[pa].second == c[pc].second) { st.insert(a[pa].second); pa --; continue; }
if(b[pb].second == c[pc].second) { st.insert(b[pb].second); pb --; continue; }
if(min({pa, pb, pc}) == -1) { break; }
if(p[a[pa].second].second.first > b[pb].first) {
st.insert(a[pa].second);
pa --;
continue;
}
if(p[a[pa].second].second.second > c[pc].first) {
st.insert(a[pa].second);
pa --;
continue;
}
if(p[b[pb].second].first > a[pa].first) {
st.insert(b[pb].second);
pb --;
continue;
}
if(p[b[pb].second].second.second > c[pc].first) {
st.insert(b[pb].second);
pb --;
continue;
}
if(p[c[pc].second].first > a[pa].first) {
st.insert(c[pc].second);
pc --;
continue;
}
if(p[c[pc].second].second.first > b[pb].first) {
st.insert(c[pc].second);
pc --;
continue;
}
ans = max(ans, a[pa].first + b[pb].first + c[pc].first);
break;
}
cout << ans << endl;
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... |