QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61676 | #2541. Coins and Boxes | yqyx | RE | 1ms | 3740kb | C++17 | 802b | 2022-11-14 15:51:11 | 2022-11-14 15:51:14 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define N 100012
#define mkp make_pair
#define pb push_back
using namespace std;
ll read(){
ll x=0,fl=1; char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-')fl=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){ x=x*10+ch-'0'; ch=getchar();}
return x*fl;
}
int n;
struct A{
int x,fl;
}a[N];
ll ans;
int cmp(A c,A d){
return c.x<d.x;
}
int main(){
n=read();
for(int i=1;i<=n;i++){
a[i].x=read(); a[i].fl=-1;
}
for(int i=1;i<=n;i++){
a[i+n].x=read(); a[i+n].fl=1;
}
n*=2;
sort(a+1,a+1+n,cmp);
a[n+1]=a[n];
ll jl=0,sum=0;
ans=a[n].x;
for(int i=1;i<=n;i++){
jl+=a[i].fl;
if(jl<0) sum+=2ll*(a[i+1].x-a[i].x);
ans=min(ans,sum+a[n].x-a[i+1].x);
}
ans+=a[n].x;
printf("%lld",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
input:
4 1 6 7 12 3 5 10 11
output:
21
result:
ok answer is '21'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
2 1 2 1 1000000000
output:
1999999998
result:
ok answer is '1999999998'
Test #3:
score: -100
Runtime Error
input:
100000 967 3246 9492 10300 15195 16650 26911 54855 83695 112841 125511 137160 153051 155859 177924 187843 214838 219388 247276 249612 250188 253873 257830 261805 281312 297030 298332 325904 333218 339683 374111 387794 396645 403705 426710 436137 463368 481801 501933 509267 511332 515225 515629 51686...