이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
const int inf = 1e9;
int get(vector<array<int,3>>&a, int idx)
{
sort(a.begin(),a.end(), [&](array<int,3>x, array<int,3>y){
return x[idx]<y[idx];
});
int mxx = a.back()[idx];
int n = a.size();
priority_queue<pair<int,int>> pqy,pqz;
for(int i=0; i<n; i++)
{
if(a[i][idx]!=mxx)
{
pqy.push({a[i][(idx+1)%3],i});
pqz.push({a[i][(idx+2)%3],i});
}
else break;
}
int ans = -1;
while(!pqy.empty() && pqy.top().second==pqz.top().second)
{
pqy.pop();
pqz.pop();
}
if(!pqy.empty())
{
ans = max(ans, mxx + pqy.top().first + pqz.top().first);
}
return ans;
}
void solve()
{
int n;
cin >> n;
vector<array<int,3>> a(n);
int mxx = 0, mxy = 0, mxz = 0;
int mnx = inf, mny = inf, mnz = inf;
for (int i = 0; i < n; i++)
{
cin >> a[i][0]>>a[i][1]>>a[i][2];
mxx = max(mxx,a[i][0]);
mxy = max(mxy,a[i][1]);
mxz = max(mxz,a[i][2]);
mnx = min(mnx, a[i][0]);
mny = min(mny, a[i][1]);
mnz = min(mnz, a[i][2]);
}
vector<array<int,3>> b;
for(int i=0; i<n; i++)
{
int cnt = 0;
if(a[i][0]==mxx) cnt++;
if(a[i][1]==mxy) cnt++;
if(a[i][2]==mxz) cnt++;
if(cnt>=2) continue;
cnt = 0;
if(a[i][0]==mnx) cnt++;
if(a[i][1]==mny) cnt++;
if(a[i][2]==mnz) cnt++;
if(cnt==3) continue;
b.push_back(a[i]);
}
swap(a,b);
n = a.size();
if(n<=2)
{
cout<<"-1\n";
return;
}
int ans = -1;
for(int i=0; i<3; i++)
{
ans = max(ans, get(a,i));
}
cout<<ans<<"\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("error.txt", "w", stderr);
// #endif
int tt = 1;
// cin >> tt;
while (tt--)
{
solve();
}
}
# | 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... |