QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303250 | #7993. 哈密顿 | C1942huangjiaxu | WA | 1ms | 3884kb | C++14 | 1015b | 2024-01-11 23:08:22 | 2024-01-11 23:08:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
int n,a[N],b[N],m,mxb,mnb,mxa,mna,pr[N],su[N];
ll ans,res;
bool v[N],fg,g[N];
struct va{
int v,id;
bool operator <(const va a)const{return v<a.v;}
}w[N<<1];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d%d",&a[i],&b[i]);
w[++m]={a[i],i},w[++m]={b[i],i};
}
sort(w+1,w+m+1);
for(int i=1;i<=n;++i){
ans-=w[i].v;
int x=w[i].id;
if(v[x])fg=true;
if(w[i].v==a[x])g[x]=true;
v[x]=true;
}
for(int i=n+1;i<=m;++i)ans+=w[i].v;
if(fg)return printf("%lld\n",ans),0;
for(int i=1;i<=n;++i){
pr[i]=pr[i-1];
if(g[i])pr[i]=max(pr[i],a[i]);
else pr[i]=max(pr[i],b[i]);
}
for(int i=n;i;--i){
su[i]=su[i+1];
if(g[i])su[i]=max(su[i],a[i]);
else su[i]=max(su[i],b[i]);
}
for(int i=1;i<=n;++i){
if(g[i])res=max(res,ans-2ll*b[i]+2ll*max(pr[i-1],su[i+1]));
else res=max(res,ans-2ll*a[i]+2ll*max(pr[i-1],su[i+1]));
}
printf("%lld\n",res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
3 1 10 8 2 4 5
output:
10
result:
ok single line: '10'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3884kb
input:
2 732734236 669531729 368612323 916696032
output:
116957610
result:
wrong answer 1st lines differ - expected: '484881202', found: '116957610'