QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#603598 | #8548. China Convex Polygon Contest | ucup-team4153 | WA | 42ms | 7040kb | C++17 | 2.5kb | 2024-10-01 17:44:51 | 2024-10-01 17:44:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const int INF=2e9;
int t,n,m;
int a[N],b[N],pre[N];
bool visa[N],visb[N];
vector<int>vec;
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
cin>>n>>m;
vec.clear();
for(int i=1;i<=n;i++){
cin>>a[i];
vec.push_back(a[i]);
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
sort(b+1,b+n+1);
for(int i=1;i<=n;i++){
b[i]+=b[i-1];
if(b[i]<=m)vec.push_back(b[i]);
}
vec.push_back(m);
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(), vec.end()),vec.end());
int cnt=vec.size();
for(int i=0;i<cnt;i++){
visa[i]=false;
visb[i]=false;
}
priority_queue<int>que;
for(int i=1;i<=n;i++){
visa[lower_bound(vec.begin(), vec.end(),a[i])-vec.begin()]=true;
if(b[i]<=m)visb[lower_bound(vec.begin(), vec.end(),b[i])-vec.begin()]=true;
}
for(int i=0,_pre=0;i<cnt;i++){
if(visa[i])_pre=i;
if(visb[i]){
pre[i]=_pre;
_pre=-1;
}
}
int res=0;
int lst=cnt-1;
for(int i=cnt-2;i>=0;i--){
if(visb[i]){
if(pre[i]==-1){
if(!que.empty()){
res+=que.top();
que.pop();
}
}else{
if(que.empty() || vec[lst]-vec[i]>que.top()){
int nxt=0;
if(!que.empty()){
nxt+=que.top();
que.pop();
}
nxt+=vec[i]-vec[pre[i]];
que.push(nxt);
res+=vec[lst]-vec[i];
lst=-1;
}else{
if(!que.empty()){
res+=que.top();
que.pop();
}
}
}
}
if(visa[i]) {
if(lst!=-1){
que.push(vec[lst]-vec[i]);
if(vec[lst]-vec[i]<0)cout<<i<<' '<<lst<<'\n';
}
lst = i;
}
}
cout<<res<<'\n';
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5916kb
input:
3 3 10 1 5 9 1 2 3 3 10 1 5 9 1 1 4 3 10 1 5 9 1 5 10
output:
9 9 7
result:
ok 3 number(s): "9 9 7"
Test #2:
score: 0
Accepted
time: 17ms
memory: 3872kb
input:
10000 9 879847766 125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083 99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599 8 30 5 12 16 19 20 23 25 27 3 1 1 4 2 8 2 3 8 30 4 10 13 16 17 20 23 27 6 3 1 2 3 4 7 2 7 586479012 37693706 ...
output:
858888761 28 27 548785306 28 875933380 27 803763192 942603170 720683076 536166430 759475944 28 27 28 886112586 27 28 28 727698126 28 27 29 28 28 28 28 27 28 819730903 755946410 28 26 28 792662140 891539003 583799124 817190966 934413263 28 28 865467960 27 27 29 488557236 27 26 618111955 28 27 8328741...
result:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 17ms
memory: 3588kb
input:
10000 8 921979410 2012452 24917627 294894613 360777223 466409663 571239725 717231773 737720960 44502046 158432459 29280108 46756101 343060886 113805663 122292234 18336789 9 996365984 93547621 418854579 432723524 452103231 472239725 534297866 551979311 643474068 796448288 94769801 184799140 40559247 ...
output:
897061783 958809789 518874667 508026272 25 817915823 563445073 755045438 917466401 26 27 963697076 28 857532778 28 28 28 599907462 733717366 861642961 553806595 802417186 26 29 29 29 26 27 908132071 816055107 862993074 29 28 27 28 882732250 585539614 900924232 28 556635369 29 890134472 29 636599530 ...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 18ms
memory: 3640kb
input:
10000 10 693426682 39824378 170753052 172063351 204664113 232271632 245840174 254784959 390184491 453231487 570861818 59595344 22173087 116391450 143121946 23632190 35151525 70352626 30324904 25656706 163522735 8 745209526 121015828 125758181 231986462 461404045 468707947 717366997 738929033 7446472...
output:
655017612 738487472 27 27 626514952 500700122 849903776 29 28 921304686 28 28 28 511049979 28 964808180 611201804 970483767 27 860011940 29 508674850 932159377 948125850 876572563 27 27 575252625 663694866 28 28 27 29 964824235 29 675855993 706402286 754992051 871698228 662676082 27 27 709260574 28 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 17ms
memory: 3588kb
input:
10000 9 842080350 126196899 281629390 459021362 589053377 623175793 685983677 686703503 729586222 758579378 139044583 175581708 4917601 53914562 1222336 149353315 84085936 136084484 1513682 10 722336436 66051155 127735998 212633619 309660895 320820247 433981470 582010812 605111593 662898478 67592938...
output:
840138188 695635705 27 488244927 611314272 28 29 776832666 523082033 510786580 29 665355993 834007553 26 28 28 27 596775460 27 601211316 508521258 27 29 618048411 550827368 28 685403346 28 548465042 28 717225955 27 28 882022106 844126870 677316532 649858373 25 28 27 559237354 27 29 497165741 28 5888...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 17ms
memory: 3876kb
input:
10000 8 708514163 23962271 40872775 157099307 187103309 187292974 402257538 501178818 704015400 25220820 70022938 15019601 105088431 93501133 257255953 42050187 77267678 7 30 3 7 14 15 18 25 28 2 2 4 2 5 4 8 10 30 1 3 6 10 14 16 18 21 23 29 1 2 1 1 1 4 3 1 9 2 8 30 6 11 15 19 20 21 26 27 1 1 2 5 12 ...
output:
684362227 27 29 27 28 793316719 779926027 705604988 27 27 29 27 762714343 590862983 651453477 27 29 906481542 609791490 655735160 825013581 27 589806786 769457681 559647071 676833126 28 28 565082202 29 29 29 605930903 736724745 496276423 735975647 27 752861191 498615546 696968479 872153866 847512710...
result:
ok 10000 numbers
Test #7:
score: 0
Accepted
time: 17ms
memory: 3872kb
input:
10000 9 30 10 13 17 20 24 26 27 28 29 2 2 2 7 1 2 1 7 1 7 831527343 75686598 280691289 496275248 534534697 652168969 665687389 764253502 41653637 35883907 77174475 169783531 134532994 338354 215483430 8 718484116 100189900 124378121 342235912 403546854 508604060 531760359 621198327 671653286 1603436...
output:
28 817670569 694754999 26 27 812629714 27 553368309 749769223 28 27 869423605 927591951 28 868501917 27 554113115 27 757872877 834811859 28 27 28 29 552439238 735169432 876903178 581459092 28 27 657892555 26 886754984 28 686160103 789538336 981411102 510312850 890648943 770480532 583276901 718986202...
result:
ok 10000 numbers
Test #8:
score: 0
Accepted
time: 17ms
memory: 3624kb
input:
10000 10 30 3 4 6 14 17 18 20 22 25 29 2 6 3 3 5 1 3 1 2 2 10 30 6 11 15 16 19 20 23 26 28 29 1 3 2 4 1 4 2 4 2 5 7 600683054 113738178 144331374 193930552 194822106 386416391 476890041 530562637 128835461 23989891 53437985 88589084 2092213 37690603 190105270 8 853858494 17017766 188244392 228267168...
output:
28 28 597699287 797386235 727159057 565049429 828474455 27 895177696 28 594056778 912193740 27 620191871 852100623 29 28 27 943358883 580553291 26 29 29 642061746 28 874798456 27 541562041 28 29 642682965 27 28 824610759 28 486459828 704550861 483902395 29 28 27 28 618648751 633419081 533827057 28 2...
result:
ok 10000 numbers
Test #9:
score: 0
Accepted
time: 14ms
memory: 5908kb
input:
10000 10 794490958 33950165 102613172 233931653 294328727 365866988 394195990 502295599 533500764 697722342 789065736 117636901 56842505 67344689 12693883 43898025 33184559 25296165 165237670 98913433 85684653 7 583412616 79630060 103778160 178797644 347021280 412084871 412242198 437485086 22767799 ...
output:
760540793 554564585 27 28 956701395 25 29 28 28 27 28 28 28 616705831 26 28 28 28 28 27 27 27 470127478 28 562109534 638390996 937834685 702323118 665789596 734137704 26 28 826636157 645678237 641375059 791320618 769654094 28 27 868850069 836416112 29 29 28 825545237 831096007 29 28 579941952 28 29 ...
result:
ok 10000 numbers
Test #10:
score: 0
Accepted
time: 17ms
memory: 3584kb
input:
10000 7 620163263 2210088 111033028 213072508 221754874 270340156 465271372 605401151 6589256 133531932 80578109 1717576 194259279 19940297 73135525 8 821458748 94147403 103911199 119213944 148910116 274334138 396035434 415716320 720330739 17483998 40595682 113502043 152348211 87133614 140810847 126...
output:
617953175 759227323 28 577328355 863285321 667218327 29 28 27 28 815536760 559280576 503382454 27 854334502 533028547 967848554 28 767236520 527447546 27 28 625532436 557267576 964127503 27 941231576 648972067 627806338 27 27 685426661 28 27 500624304 27 896818489 29 29 762801184 27 28 27 28 28 7797...
result:
ok 10000 numbers
Test #11:
score: 0
Accepted
time: 14ms
memory: 3584kb
input:
10000 8 748462261 126938743 298205026 460858560 493696867 561517982 598369982 611594963 660762051 9836010 43420294 113911448 87081999 64171127 65191414 117828249 86952635 9 818975929 111152475 125419210 135487970 248358986 365050068 500993620 620295174 693052429 740583941 4529198 15575283 36039923 1...
output:
725401270 790111236 28 742737637 803407267 947164183 576552794 29 27 28 29 28 28 874730861 27 855768639 26 28 911087029 26 28 27 583592147 28 813229697 26 614462355 28 514365649 28 621277915 27 472160914 860353209 559573286 28 27 728087897 26 726726326 28 29 855714743 880622108 27 28 924203964 27 85...
result:
ok 10000 numbers
Test #12:
score: 0
Accepted
time: 18ms
memory: 3624kb
input:
10000 8 796414787 31461520 50761715 90495707 251124998 341850881 720825960 773620389 780205466 54722380 216907544 23636692 98146858 23139876 206884562 69929854 45979367 8 870995852 157940387 214396482 255563234 292144526 336132163 634226211 655076826 795592633 219513340 91244154 123598065 6795235 13...
output:
762693039 806768710 736355372 26 28 28 729100973 862887449 570384939 28 594631648 676565090 28 913095700 562500308 673390494 28 28 655289472 27 28 28 28 29 888685546 690676876 835447840 632836562 666794814 28 908883242 864921023 643425480 652704139 29 893801977 848367692 681211139 760058749 61436934...
result:
ok 10000 numbers
Test #13:
score: 0
Accepted
time: 36ms
memory: 6200kb
input:
1 93849 788867517 27106 35801 44166 45367 71580 75909 79832 80217 88191 125196 128361 161338 162562 166454 169706 187030 193620 198170 213307 218172 219965 224851 227874 234787 249446 254210 260203 261675 266494 275046 281192 287637 294087 302671 329113 334903 352098 375155 393228 400443 406748 4227...
output:
788867514
result:
ok 1 number(s): "788867514"
Test #14:
score: 0
Accepted
time: 37ms
memory: 6384kb
input:
1 96398 922474561 1901 2788 13435 21334 21715 32835 37906 50378 60713 63368 72102 79312 89180 93296 98588 109931 111175 112094 128772 131828 133586 135397 138806 139916 144874 153088 182296 199243 203880 203963 204287 206706 206814 212347 219070 224608 228339 232690 244468 250015 252724 266841 27237...
output:
922474558
result:
ok 1 number(s): "922474558"
Test #15:
score: 0
Accepted
time: 34ms
memory: 5976kb
input:
1 90089 742727663 1217 6823 13314 18050 24731 28352 42997 49561 55040 61758 70988 83872 92015 94583 130355 130462 134637 140652 144576 145902 148292 155581 155868 166731 177106 194744 209712 231894 232938 236413 240680 241753 243178 243375 250977 269081 271541 276802 298463 305980 312949 318614 3306...
output:
742727661
result:
ok 1 number(s): "742727661"
Test #16:
score: 0
Accepted
time: 35ms
memory: 6496kb
input:
1 91457 958286812 4576 10232 12013 36690 43036 75552 78919 83507 87580 95811 98869 103602 117510 124332 134780 145656 146869 149969 154497 155954 166010 181781 197212 200887 221994 232743 244628 247812 269153 275367 277923 279230 306333 311159 311796 313583 315548 326592 339643 353158 355861 410756 ...
output:
958286810
result:
ok 1 number(s): "958286810"
Test #17:
score: 0
Accepted
time: 40ms
memory: 6376kb
input:
1 96636 946300936 1934 10123 19340 33428 51855 58257 62986 64601 69149 84284 86204 100279 108754 109464 116710 125731 142727 155341 195026 227414 235495 248717 251184 296436 297163 300170 301264 312881 317358 332543 333984 372889 376568 391504 405260 410727 415870 436541 442341 446510 449309 460153 ...
output:
946300933
result:
ok 1 number(s): "946300933"
Test #18:
score: 0
Accepted
time: 40ms
memory: 6284kb
input:
1 94463 828132301 542 7003 17038 17374 25312 35177 36656 45415 56758 61075 63587 69933 80702 85732 88898 90611 92986 102266 119807 130948 144192 144289 168919 177198 180392 184131 198442 198628 208736 209804 223497 224487 233230 250463 252862 253768 276441 281549 292476 304007 304196 307425 311458 3...
output:
828132298
result:
ok 1 number(s): "828132298"
Test #19:
score: 0
Accepted
time: 42ms
memory: 6256kb
input:
1 99386 856358032 9342 9789 15768 18347 29826 32298 37146 38716 40663 47080 58496 77227 80563 86981 87770 88422 93717 108195 109329 123588 131010 146152 148141 151411 154282 167351 176879 200229 200934 204370 207654 211060 213202 231489 235581 243411 245746 247478 255086 256528 272684 294411 307780 ...
output:
856358030
result:
ok 1 number(s): "856358030"
Test #20:
score: 0
Accepted
time: 34ms
memory: 7040kb
input:
1 99942 623445854 982 3331 10251 12748 30485 32159 49296 50512 55319 55687 82035 82574 94924 96836 99176 102414 103630 110474 111946 118759 120206 123390 129224 129298 136940 158783 164951 172817 174836 178804 184460 191101 191325 197909 217538 220281 231269 237586 239146 241407 250407 251311 259801...
output:
623445852
result:
ok 1 number(s): "623445852"
Test #21:
score: 0
Accepted
time: 41ms
memory: 6376kb
input:
1 95819 844006123 11453 12062 15525 20176 21653 41258 47316 60272 66576 93784 112286 119375 124809 132817 133053 135731 153151 154062 157182 157782 164364 169065 172029 173121 183564 192849 212900 213437 216589 224462 226749 235646 263949 272370 274975 274998 276231 281002 291211 311728 313567 31970...
output:
844006121
result:
ok 1 number(s): "844006121"
Test #22:
score: 0
Accepted
time: 40ms
memory: 6260kb
input:
1 93880 546964419 2938 9927 12958 13151 15391 15718 15812 18174 19487 23743 25343 30417 33954 36426 37278 43055 47143 51426 51900 53292 57316 72434 73105 74128 84406 85453 87082 90728 91445 93245 101854 105770 112370 119339 127949 135934 136058 138343 142476 146026 151741 155635 157622 159642 160008...
output:
546964417
result:
ok 1 number(s): "546964417"
Test #23:
score: 0
Accepted
time: 42ms
memory: 6976kb
input:
1 98812 961793551 3616 12679 15790 22833 33885 41959 70817 78699 85656 112851 128769 130690 136491 146925 154819 186242 189811 190091 195553 208681 231515 240489 263384 290850 292743 294292 305578 308416 309301 310271 314676 332338 337413 341230 346650 349548 352528 353891 364497 365545 380945 38191...
output:
961793548
result:
ok 1 number(s): "961793548"
Test #24:
score: -100
Wrong Answer
time: 25ms
memory: 6456kb
input:
1 100000 1000000000 5000 10000 15000 20000 25000 30000 35000 40000 45000 50000 55000 60000 65000 70000 75000 80000 85000 90000 95000 100000 105000 110000 115000 120000 125000 130000 135000 140000 145000 150000 155000 160000 165000 170000 175000 180000 185000 190000 195000 200000 205000 210000 215000...
output:
-1228837176
result:
wrong answer 1st numbers differ - expected: '749990000', found: '-1228837176'