이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MAX_N = 2e5 + 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(min({pa, pb, pc}) == -1) { break; }
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(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... |