求助一半AC一半WA
查看原帖
求助一半AC一半WA
1037502
luxiaomao楼主2023/8/17 21:06
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int a,b,c;
priority_queue<pair<int,int>,vector<pair<int,int> >,less<pair<int,int> > > x,y,z;
bool vis[150005];
int maxx = 0;

signed main(){
    scanf("%lld",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%lld%lld%lld",&a,&b,&c);
        x.push(make_pair(a,i));
        y.push(make_pair(b,i));
        z.push(make_pair(c,i));
    }
    memset(vis,0,sizeof(vis));
    while(true)
    {
        while(!x.empty()&&vis[x.top().second])x.pop();
        while(!y.empty()&&vis[y.top().second])y.pop();
        while(!z.empty()&&vis[z.top().second])z.pop();
        if(x.empty()&&y.empty()&&z.empty()){
            printf("-1");
            return 0;
        }
		if(x.top().second==y.top().second && y.top().second==z.top().second){
            vis[x.top().second] = true;
			x.pop();
            y.pop();
            z.pop();
        }
        else if(x.top().second==y.top().second){
            vis[x.top().second] = true;
			x.pop();
            y.pop();
        }
        else if(x.top().second==z.top().second){
            vis[x.top().second] = true;
			x.pop();
            z.pop();
        }
        else if(y.top().second==z.top().second){
            vis[y.top().second] = true;
			y.pop();
            z.pop();
        }
        else{
            maxx=max(maxx,x.top().first+y.top().first+z.top().first);
            break;
        }
    }
    printf("%lld",maxx);
    return 0;
}
2023/8/17 21:06
加载中...