QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#483344 | #2541. Coins and Boxes | GenshinImpactsFault | AC ✓ | 14ms | 4532kb | C++14 | 715b | 2024-07-18 16:01:49 | 2024-07-18 16:01:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int n;
int a[N], b[N];
ll ans, pre;
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) cin >> a[i];
int cnt = 0;
ans = max(a[n], b[n]) * 2;
for(int i = 1, j = 1; i <= n || j <= n;) {
if(j > n || (i <= n && a[i] <= b[j])) {
++cnt;
if(cnt == 0) {
pre += a[i] * 2;
}
++i;
}
else {
--cnt;
if(cnt == -1) {
ans = min(ans, pre + max(a[n], b[n]) * 2 - b[j]);
pre -= 2 * b[j];
}
++j;
}
}
ans = min(ans, pre + max(a[n], b[n]));
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
4 1 6 7 12 3 5 10 11
output:
21
result:
ok answer is '21'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
2 1 2 1 1000000000
output:
1999999998
result:
ok answer is '1999999998'
Test #3:
score: 0
Accepted
time: 14ms
memory: 4408kb
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: 13ms
memory: 4404kb
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: 9ms
memory: 4468kb
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: 0
Accepted
time: 12ms
memory: 4532kb
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:
1999997448
result:
ok answer is '1999997448'
Test #7:
score: 0
Accepted
time: 13ms
memory: 4468kb
input:
99996 25026 29314 38031 55515 58248 91136 92169 96094 121944 125408 128114 132454 161511 163448 180284 187634 187712 197908 213086 215259 226892 228655 229530 229634 231044 238690 240124 269294 272040 275538 282733 295680 308328 320763 332616 348362 353637 374734 381391 399553 419842 436962 446125 4...
output:
1621365600
result:
ok answer is '1621365600'
Test #8:
score: 0
Accepted
time: 12ms
memory: 4520kb
input:
99995 10223 16977 27104 30366 33888 68266 69393 77516 83525 90589 92718 100214 115458 134626 140528 144660 149129 154368 155587 167426 172691 173557 177615 180672 189254 201599 206935 221085 225893 230510 231327 234890 237209 257538 269006 270538 272229 285101 285209 304541 306350 306470 308729 3159...
output:
1999907494
result:
ok answer is '1999907494'
Test #9:
score: 0
Accepted
time: 13ms
memory: 4464kb
input:
99994 18495 22067 52316 52641 62295 62911 69914 76550 80066 80071 81729 90913 101460 109732 111327 119704 135376 151365 176005 177246 190409 213505 221735 249555 259122 270413 272412 273176 274430 283913 287207 296418 303688 305251 315266 318243 325192 335178 380426 408808 417444 422256 481428 48803...
output:
1913993204
result:
ok answer is '1913993204'
Test #10:
score: 0
Accepted
time: 12ms
memory: 4400kb
input:
99993 1070 14668 21352 34109 38906 40069 73849 87380 90226 90550 100067 102253 102624 135890 157425 158371 175085 196385 204891 208948 212980 216546 218542 249641 254587 260679 272486 276645 276725 299497 306999 308019 325890 339400 347511 353236 355905 364588 392409 411574 416800 426703 434794 4361...
output:
1632595662
result:
ok answer is '1632595662'
Test #11:
score: 0
Accepted
time: 12ms
memory: 4460kb
input:
99992 11870 36989 42564 51483 80118 101015 107977 116637 134719 135952 136980 143605 144477 149138 159719 168394 172644 177631 206953 212080 217045 219915 223030 227213 234544 254268 257162 273753 274263 280730 283934 291351 314592 330037 359349 366319 370533 371573 378133 382552 385392 385975 38603...
output:
1999467239
result:
ok answer is '1999467239'
Test #12:
score: 0
Accepted
time: 12ms
memory: 4532kb
input:
99991 5832 32811 36438 39640 41689 47294 58009 66270 75037 78414 88263 95628 96362 107552 114809 119586 129877 140294 143702 156882 174562 185461 201452 209857 234793 244676 264930 271103 274443 277954 284390 290387 293917 294126 297087 314692 321325 337431 438631 448151 452480 452971 459336 460070 ...
output:
1979555334
result:
ok answer is '1979555334'
Test #13:
score: 0
Accepted
time: 8ms
memory: 4480kb
input:
100000 204996 214994 224992 234990 244988 254986 264984 274982 284980 294978 304976 314974 324972 334970 344968 354966 364964 374962 384960 394958 404956 414954 424952 434950 444948 454946 464944 474942 484940 494938 504936 514934 524932 534930 544928 554926 564924 574922 584920 594918 604916 614914...
output:
1999795001
result:
ok answer is '1999795001'
Test #14:
score: 0
Accepted
time: 12ms
memory: 4408kb
input:
100000 204996 214994 224992 234990 244988 254986 264984 274982 284980 294978 304976 314974 324972 334970 344968 354966 364964 374962 384960 394958 404956 414954 424952 434950 444948 454946 464944 474942 484940 494938 504936 514934 524932 534930 544928 554926 564924 574922 584920 594918 604916 614914...
output:
1999795001
result:
ok answer is '1999795001'
Test #15:
score: 0
Accepted
time: 12ms
memory: 4476kb
input:
100000 818861232 818861420 818861674 818861727 818862837 818863680 818864026 818871230 818871575 818871696 818871950 818872374 818873150 818873796 818881228 818881320 818881983 818882921 818883218 818884049 818884162 818891226 818891933 818892334 818892710 818893493 818893589 818893915 818894060 818...
output:
1181138765
result:
ok answer is '1181138765'
Test #16:
score: 0
Accepted
time: 8ms
memory: 4468kb
input:
100000 69996 72107 74802 80861 82501 83196 83873 83929 88398 90491 169994 174680 176359 177432 178787 178871 181623 183255 184947 189557 269992 270072 270722 276256 277314 280435 282604 286375 290855 290904 369990 370446 373585 376121 378877 378915 379349 389288 396361 400391 469988 475084 481369 48...
output:
1999930001
result:
ok answer is '1999930001'
Test #17:
score: 0
Accepted
time: 12ms
memory: 4520kb
input:
100000 980408916 980408952 980409038 980409039 980409050 980409057 980409092 980409137 980409198 980409257 980409288 980409295 980409305 980409306 980409336 980409353 980409361 980409396 980409440 980409448 980409489 980409563 980409574 980409580 980409628 980409669 980409739 980409757 980409814 980...
output:
1019591081
result:
ok answer is '1019591081'
Test #18:
score: 0
Accepted
time: 12ms
memory: 4396kb
input:
100000 501996 504573 504675 506801 507441 510426 512837 513648 516765 516913 524113 524644 524685 527636 544345 545688 548308 556295 556895 557921 558524 559327 566578 569076 569202 569641 570723 575404 576393 578399 579547 584312 588093 590836 591548 593973 595809 598531 598831 602029 606655 612996...
output:
1999498001
result:
ok answer is '1999498001'
Test #19:
score: 0
Accepted
time: 12ms
memory: 4532kb
input:
100000 997985400 997985401 997985402 997985403 997985405 997985406 997985409 997985419 997985422 997985425 997985434 997985444 997985446 997985447 997985456 997985457 997985465 997985467 997985469 997985475 997985476 997985478 997985481 997985487 997985489 997985490 997985491 997985494 997985497 997...
output:
1002014597
result:
ok answer is '1002014597'
Test #20:
score: 0
Accepted
time: 13ms
memory: 4480kb
input:
100000 5000196 5002498 5009443 5013105 5020071 5020745 5027505 5034151 5037789 5037906 5041838 5043212 5044213 5044437 5045859 5045983 5049093 5049776 5054802 5066114 5066778 5077363 5078723 5081460 5081918 5083572 5083592 5085115 5091353 5092299 5092862 5098424 5101292 5102871 5104581 5104648 51047...
output:
1994999801
result:
ok answer is '1994999801'
Test #21:
score: 0
Accepted
time: 12ms
memory: 4468kb
input:
100000 999339997 999339998 999339999 999340000 999340004 999340006 999340008 999340012 999340013 999340014 999340015 999340016 999340019 999340022 999340023 999340024 999340029 999340031 999340035 999340038 999340039 999340040 999340041 999340042 999340044 999340045 999340046 999340047 999340049 999...
output:
1000660000
result:
ok answer is '1000660000'
Test #22:
score: 0
Accepted
time: 8ms
memory: 4400kb
input:
100000 50000016 50001330 50001828 50003554 50008855 50010928 50015513 50016422 50018812 50020958 50022265 50024787 50025917 50027599 50027684 50028653 50032933 50035305 50036367 50037907 50040763 50043425 50043695 50045291 50051654 50052192 50053899 50054003 50054756 50054759 50056684 50059912 50060...
output:
1949999981
result:
ok answer is '1949999981'
Test #23:
score: 0
Accepted
time: 8ms
memory: 4516kb
input:
99999 214996 224994 234992 244990 254988 264986 274984 284982 294980 304978 314976 324974 334972 344970 354968 364966 374964 384962 394960 404958 414956 424954 434952 444950 454948 464946 474944 484942 494940 504938 514936 524934 534932 544930 554928 564926 574924 584922 594920 604918 614916 624914 ...
output:
999995001
result:
ok answer is '999995001'
Test #24:
score: 0
Accepted
time: 12ms
memory: 4480kb
input:
99990 169996 171724 178382 178476 182068 183020 183383 193442 196303 197124 269994 274417 280102 283478 285323 285787 288496 291940 293082 293342 369992 373923 376796 378417 379849 381060 381133 385906 387318 390190 469990 470158 477128 483642 484270 488208 488953 489331 495925 496509 569988 575671 ...
output:
999983609
result:
ok answer is '999983609'
Test #25:
score: 0
Accepted
time: 12ms
memory: 4452kb
input:
99900 1501996 1502909 1502946 1504704 1505467 1512967 1513115 1517811 1521379 1522486 1528142 1530150 1531066 1531845 1533372 1533871 1539915 1540657 1542388 1542849 1542958 1549235 1549772 1549926 1551186 1552619 1552700 1553059 1553486 1555270 1556981 1561059 1563420 1567895 1568963 1573950 157589...
output:
999729031
result:
ok answer is '999729031'
Test #26:
score: 0
Accepted
time: 12ms
memory: 4480kb
input:
100000 204997 214996 224994 234992 244990 254988 264986 274984 284982 294980 304978 314976 324974 334972 344970 354968 364966 374964 384962 394960 404958 414956 424954 434952 444950 454948 464946 474944 484942 494940 504938 514936 524934 534932 544930 554928 564926 574924 584922 594920 604918 614916...
output:
1999795001
result:
ok answer is '1999795001'
Test #27:
score: 0
Accepted
time: 12ms
memory: 4464kb
input:
100000 69997 72245 72594 77237 78686 87082 87481 87769 90177 91443 169996 170542 170581 173449 176051 187115 191481 191819 192772 195697 269994 277168 279571 280444 280581 281859 283006 288092 288102 302350 369992 370128 370677 371784 373305 375221 377207 380953 388797 389023 469990 473805 479469 48...
output:
1999930001
result:
ok answer is '1999930001'
Test #28:
score: 0
Accepted
time: 12ms
memory: 4460kb
input:
100000 501997 503290 504580 508654 512077 515587 516203 517874 522659 525802 526667 527049 530499 532881 534076 540003 540814 541964 544659 545291 546185 547964 550831 557408 559329 563365 564709 565498 568974 570843 582127 586172 587361 589937 590684 591143 591761 596758 597589 598512 603183 605167...
output:
1999498001
result:
ok answer is '1999498001'