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>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
#define pow poww
const int M=5100;
const ll mod=998244353;
const ll inf=2e18;
const ll dx[]={1,-1,0,0};
const ll dy[]={0,0,1,-1};
ll pow(ll x,ll y){
ll res=1;
x%=mod;
while(y>0){
if(y%2==1){
res*=x,res%=mod;
}
x*=x,x%=mod;
y/=2;
}
return res;
}
ll nn,n,ma[M][M],a[M],b[M],c[M],rv1[M],rv2[M],rv3[M];
ll mp[301][301][301];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
ll TC=1;
//cin>>TC;
while(TC--){
cin>>nn;
for(int i=0;i<nn;i++){
ll x,y,z;
cin>>x>>y>>z;
mp[x][y][z]=1;
}
for(int i=0;i<301;i++){
for(int j=0;j<301;j++){
for(int k=0;k<301;k++){
if(mp[i][j][k])
a[n++]=i,b[n-1]=j,c[n-1]=k;
}
}
}
for(int i=0;i<n;i++)
ma[a[i]][b[i]]=max(ma[a[i]][b[i]],c[i]);
for(int i=0;i<=300;i++){
for(int j=1;j<=300;j++)
ma[i][j]=max(ma[i][j-1],ma[i][j]);
}
for(int j=0;j<=300;j++){
for(int i=1;i<=300;i++)
ma[i][j]=max(ma[i][j],ma[i-1][j]);
}
ll ans=-1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
continue;
if(a[i]==a[j]||b[i]==b[j])
continue;
if(((a[i]>a[j])^(b[i]>b[j]))==0)
continue;
if(ma[max(a[i],a[j])-1][max(b[i],b[j])-1]<=max(c[i],c[j]))
continue;
ans=max(ans,max(a[i],a[j])+max(b[i],b[j])+ma[max(a[i],a[j])-1][max(b[i],b[j])-1]);
}
}
cout<<ans;
}
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... |