QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61678 | #2541. Coins and Boxes | yqyx | WA | 46ms | 7068kb | C++17 | 780b | 2022-11-14 15:51:42 | 2022-11-14 15:53:52 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define N 500012
#define mkp make_pair
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: 3ms
memory: 3668kb
input:
4 1 6 7 12 3 5 10 11
output:
21
result:
ok answer is '21'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
2 1 2 1 1000000000
output:
1999999998
result:
ok answer is '1999999998'
Test #3:
score: 0
Accepted
time: 31ms
memory: 5824kb
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...
output:
1722240547
result:
ok answer is '1722240547'
Test #4:
score: 0
Accepted
time: 35ms
memory: 6240kb
input:
99999 21462 34020 34146 53248 90164 92224 98994 104980 115343 128362 134989 136436 149380 154685 181264 182990 205001 209721 213620 233438 238959 247963 248072 250838 259705 264873 265121 298034 298867 304937 325609 325758 334451 341321 363426 374659 396164 414311 424279 445253 454970 482336 505116 ...
output:
1469284712
result:
ok answer is '1469284712'
Test #5:
score: 0
Accepted
time: 46ms
memory: 6620kb
input:
99998 662 69065 90516 119024 146215 146391 152295 166603 168318 170511 185082 191597 203549 220156 222019 233462 233502 235131 247440 254351 278648 283202 287150 312840 318686 332272 344963 374235 386478 390405 391828 421104 424282 437621 438490 444582 448853 455370 468914 482565 507931 528031 53129...
output:
1782189953
result:
ok answer is '1782189953'
Test #6:
score: -100
Wrong Answer
time: 33ms
memory: 7068kb
input:
99997 1036 12224 16393 26262 26675 29724 38487 44675 52169 56398 62749 104395 122412 123854 140544 184458 187993 191357 204244 216509 225345 225651 229547 231850 240978 243269 250984 255594 271277 281251 286151 300018 301497 302196 302973 310350 321582 323564 328049 332303 335816 352755 356321 35992...
output:
1999998484
result:
wrong answer expected '1999997448', found '1999998484'