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>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long int ll;
ll n,z,t,i,j,x,y,a[1100000];
pair<ll,pair<ll,ll>> p[1100000];
map<pair<ll,pair<ll,ll>>,ll> m;
vector<pair<ll,ll>> u;
vector<pair<pair<ll,ll>,ll>> v[1100000];
set<pair<pair<ll,ll>,ll>> s;
int main()
{
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
scanf("%lld %lld %lld",&x,&y,&z);
if(m[{x,{y,z}}]==1)
continue;
t++;
p[t]={x,{y,z}};
}
z=0;
n=t;
sort(p+1,p+n+1);
for(i=1;i<=n;i++)
{
s.insert({p[i].second,i});
for(auto l=s.begin();l!=s.end();l++)
v[i+1].push_back((*l));
}
for(i=1;i<=n;i++)
{//printf("%lld",i);
t=0;
u.clear();
for(j=0;j<(i-1);j++)
{
if(p[v[i][j].second].first==p[i].first)
continue;
if(v[i][j].first.first>p[i].second.first||v[i][j].first.second>p[i].second.second)
{u.push_back(v[i][j].first); t++; }
}
for(j=0;j<t;j++)
{
if(j==0)
a[j]=u[j].second;
else
a[j]=max(a[j-1],u[j].second);
}
for(j=t-1;j>=1;j--)
{
if(u[j].second<a[j-1])
{
z=max(z,u[j].first+a[j-1]+p[i].first);
break;
}
}
}
if(z==0)
z=-1;
printf("%lld",z);
}
Compilation message (stderr)
team.cpp: In function 'int main()':
team.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
team.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%lld %lld %lld",&x,&y,&z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |