| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1370343 | pirmyratg | Team Contest (JOI22_team) | C++20 | 63 ms | 8916 KiB |
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
#define mm make_pair
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 200007;
pll a[N], b[N], c[N];
int n, p[N][2], ctr[3];
bool d[N][2];
bool f1(pll u, pll v){
if(u.ff!=v.ff) return u.ff>v.ff;
return p[u.ss][0]<p[v.ss][0];
}
bool f2(pll u, pll v){
if(u.ff!=v.ff) return u.ff>v.ff;
return c[u.ss].ff>c[v.ss].ff;
}
int main(){
scanf("%d", &n);
for(int i=1;i<=n;++i){
scanf("%lld%lld%lld", &a[i].ff, &b[i].ff, &c[i].ff);
a[i].ss=b[i].ss=c[i].ss=i;
}
sort(a+1, a+n+1, greater<pll>());
sort(b+1, b+n+1, f2);
for(int i=1;i<=n;++i) p[b[i].ss][0]=i;
sort(c+1, c+n+1, f1);
for(int i=1;i<=n;++i) p[c[i].ss][1]=i;
ctr[0]=ctr[1]=ctr[2]=1;
for(int i=1;i<=n;++i){
while(ctr[2]<=n && a[ctr[2]].ff==a[i].ff){
int id=a[ctr[2]].ss;
d[p[id][0]][0]=d[p[id][1]][1]=1;
ctr[2]++;
}
while(1){
for(int j=0;j<2;++j){
while(ctr[j]<=n && d[ctr[j]][j]) ctr[j]++;
if(ctr[j]>n){puts("-1"); return 0;}
}
if(b[ctr[0]].ss!=c[ctr[1]].ss) break;
d[ctr[0]][0]=d[ctr[1]][1]=1;
}
if(b[ctr[0]].ff>b[p[a[i].ss][0]].ff && c[ctr[1]].ff>c[p[a[i].ss][1]].ff){
printf("%lld\n", a[i].ff+b[ctr[0]].ff+c[ctr[1]].ff);
return 0;
}
}
return 0;
}Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
