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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<type1, null_type, less_equal<type1>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
using namespace __gnu_pbds;
const int mod = 998244353;
const double PI = acos(-1.0);
const double epsilon = 1e-6;
const int N = 1.5e5+5;
int n;
vector<pair<int,int> > a(N),b(N),c(N);
void solve(){
cin >> n;
vector<int> x(n),y(n),z(n);
for(int i = 0; i < n; i++){
cin >> x[i] >> y[i] >> z[i];
a[i] = {x[i],i};
b[i] = {y[i],i};
c[i] = {z[i],i};
}
sort(rall(a)); sort(rall(b)); sort(rall(c));
int posx = 0,posy = 0,posz = 0;
while(posx < n && posy < n && posz < n){
auto [xv,pos1] = a[posx];
auto [yv,pos2] = b[posy];
auto [zv,pos3] = c[posz];
if(y[pos1] >= yv || z[pos1] >= zv) posx++;
else if(x[pos2] >= xv || z[pos2] >= zv) posy++;
else if(x[pos3] >= xv || y[pos3] >= yv) posz++;
else{
cout << xv + yv + zv << '\n';
return;
}
}
cout << "-1\n";
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
}
Compilation message (stderr)
team.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main(){
| ^~~~
# | 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... |