QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368791 | #7567. Joining Cats | skyline# | AC ✓ | 177ms | 4140kb | C++17 | 1.6kb | 2024-03-27 16:30:38 | 2024-03-27 16:30:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9 + 10;
const int MAXN = 5e3 + 10;
int N,K;
int W[MAXN];
int S[MAXN];
int L[MAXN];
int newL[MAXN];
int R[MAXN];
int newR[MAXN];
int sum[MAXN];
signed main(){
scanf("%lld %lld",&N,&K);
for(int i = 1;i <= N; i++) scanf("%lld",&W[i]);
for(int i = 1;i <= K; i++) scanf("%lld",&S[i]);
for(int i = 1;i <= N; i++){
L[i] = R[i] = i;
}
for(int i = 1;i <= N; i++){
sum[i] = sum[i-1] + W[i];
//cout<<i<<" "<<sum[i]<<"#"<<endl;
}
for(int k = 1;k <= K; k++){
for(int i = 1;i <= N; i++){
newL[i] = L[i];
newR[i] = R[i];
}
int pnt = 0;
for(int i = 1;i <= N; i++){
while(pnt < N && sum[pnt + 1] - sum[R[i]] <= S[k]){
pnt++;
newL[pnt] = min(newL[pnt],i);
}
//cout<<i<<" "<<pnt<<"!!!"<<" "<<R[i]<<" "<<sum[pnt+1] - sum[R[i]]<<endl;
newR[i] = max(newR[i],pnt);
}
pnt = N + 1;
for(int i = N;i >= 1; i--){
while(pnt >= 2 && sum[L[i] - 1] - sum[pnt - 2] <= S[k]){
pnt--;
newR[pnt] = max(newR[pnt],i);
}
//cout<<i<<" "<<pnt<<"???"<<endl;
newL[i] = min(newL[i],pnt);
}
for(int i = 1;i <= N; i++){
L[i] = newL[i];
R[i] = newR[i];
}
}
// for(int i = 1;i <= N; i++){
// cout<<L[i]<<" "<<R[i]<<endl;
// }
if(R[1] == N || L[N] == 1){
printf("Yes\n");
}
else printf("No\n");
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3892kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
6 7 3 2 1 1 2 3 2 2 2 2 2 2 2
output:
No
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
7 4 1 2 3 4 3 2 1 3 3 3 3
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 139ms
memory: 4088kb
input:
5000 5000 775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...
output:
No
result:
ok answer is NO
Test #6:
score: 0
Accepted
time: 143ms
memory: 4084kb
input:
5000 5000 719129447 937392296 350445117 783330021 802155515 695380072 535475671 613171233 926763173 500405367 828284512 931492995 720877462 919465915 260912626 876806990 884762137 576596567 928561233 974405439 891740632 540536614 879167622 725668608 801467926 601260355 706621299 926987536 994204742 ...
output:
No
result:
ok answer is NO
Test #7:
score: 0
Accepted
time: 145ms
memory: 4060kb
input:
5000 5000 416747559 657602574 449451106 121890071 441124856 144632709 177533820 169507188 105623279 399624204 458468079 481561977 54065647 407303452 627276664 15195167 482406549 98222656 788603298 66301460 298650558 502696353 90244701 498415278 210561025 368288994 77615125 176971936 438514087 804772...
output:
No
result:
ok answer is NO
Test #8:
score: 0
Accepted
time: 17ms
memory: 3968kb
input:
1000 5000 652378395 9226710 369514617 603608037 161741291 783580574 951641399 734721388 223516311 671669592 479702806 414081589 624003108 605424248 896097938 156346340 669596794 597103379 732027711 334398013 586620215 764336953 962550397 952888036 385377097 271706418 466047181 667473147 451787252 34...
output:
Yes
result:
ok answer is YES
Test #9:
score: 0
Accepted
time: 19ms
memory: 3936kb
input:
1000 5000 872227273 712283986 920948311 507385120 918594985 900251115 743516868 670907467 867435817 714475407 652551933 758876839 384367533 880301180 841974114 886109922 903272749 893904997 942686977 997058175 645506447 529091876 716946215 871179658 785614131 908004811 934740746 911599923 901612611 ...
output:
Yes
result:
ok answer is YES
Test #10:
score: 0
Accepted
time: 16ms
memory: 3888kb
input:
1000 5000 101221549 613813024 32283618 57848367 218671138 83846718 546915747 208915568 65619698 104572490 576248450 591458709 44189059 290360076 189086077 191457437 54318230 363455304 196546244 548385206 78485380 617280233 259809060 837752521 143584483 370863408 173419156 323661623 35630081 19426238...
output:
Yes
result:
ok answer is YES
Test #11:
score: 0
Accepted
time: 35ms
memory: 3988kb
input:
5000 1000 384600324 423088534 580011180 18888296 867263085 174486497 579265523 677106522 109080438 243659201 879794825 2734387 317935969 351036145 597636151 139952929 616539853 427107451 467123241 455242831 725282652 898994059 618761912 184726542 957829503 458946364 808393477 865906485 986478739 254...
output:
No
result:
ok answer is NO
Test #12:
score: 0
Accepted
time: 35ms
memory: 4068kb
input:
5000 1000 815377947 795966497 973863440 950044920 825108167 536452850 291112961 631853166 506218010 935798593 775113558 699401829 880383613 914704745 782591416 917669693 708026290 459226993 668663128 910039920 841586352 784964960 888459540 302038322 659730234 805572069 846275367 852703409 775521351 ...
output:
No
result:
ok answer is NO
Test #13:
score: 0
Accepted
time: 34ms
memory: 4032kb
input:
5000 1000 5410336 393698641 500773894 760031044 646621826 839580211 65305975 201814752 180712432 120809208 163818904 82473446 457782197 21160078 17186078 215123683 176709095 456087785 326581971 310290921 168653566 481253103 321257970 84515932 243535065 236109465 60226866 102687808 41257836 127984905...
output:
No
result:
ok answer is NO
Test #14:
score: 0
Accepted
time: 133ms
memory: 4140kb
input:
5000 5000 15093311 329597379 555558975 156779227 62866262 160365196 114014190 248402694 204959438 271068381 399857257 387200774 160688159 271392845 128942838 158633588 10588789 191195688 113594413 649475911 58675835 141948582 145184928 141129342 341594247 628691612 444930099 62485843 137320414 79235...
output:
Yes
result:
ok answer is YES
Test #15:
score: 0
Accepted
time: 177ms
memory: 4008kb
input:
5000 5000 477529887 756849767 625522592 944282843 189025536 780233105 718317626 604366715 944549056 588153327 554003718 861599264 669060580 782705515 966292796 932546478 784316515 903419524 259862391 677467467 214380162 527818442 560973007 946847495 843064055 624959284 944812230 939353394 970748521 ...
output:
No
result:
ok answer is NO
Test #16:
score: 0
Accepted
time: 13ms
memory: 3944kb
input:
1000 5000 325574292 102270354 46216300 32942952 508103079 191913034 609714603 818365900 325049151 156757518 75168501 313902528 82915491 165046883 81073599 194096733 24019640 86346975 61139326 578842271 239372667 581250376 470949194 47949417 121664357 184388214 304047655 135099293 14499837 311933996 ...
output:
Yes
result:
ok answer is YES
Test #17:
score: 0
Accepted
time: 24ms
memory: 3956kb
input:
1000 5000 867019070 634631224 616990385 436336941 698141136 302442938 510047987 433825968 602529602 393200901 816058983 650168038 465885793 838694825 988063665 945400513 617709247 838863094 951999777 922224521 751597816 988527056 878463260 930696432 823011021 936615604 551149310 922193900 339772800 ...
output:
No
result:
ok answer is NO
Test #18:
score: 0
Accepted
time: 69ms
memory: 4080kb
input:
5000 1000 12914763 185952866 274462859 391168629 87559985 12451610 90187607 304282631 670146630 195684513 25052180 125646017 336091392 716771179 23532794 153946479 217505814 120969608 222036027 219127925 3797591 251515519 196704816 251535003 104406582 8668555 45713071 80107743 434698209 158289873 67...
output:
No
result:
ok answer is NO
Test #19:
score: 0
Accepted
time: 49ms
memory: 4064kb
input:
5000 1000 843422213 718313735 717253775 350095578 781242226 806054909 378670603 997836539 944108571 869165188 832295701 543856191 914809162 889177906 977791040 664634257 337858147 743113537 938707019 704311406 916809355 970510378 856434648 752091912 783396230 949977023 882274775 870528103 899447373 ...
output:
No
result:
ok answer is NO
Test #20:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
1 5000 488374113 818025693 971614891 408737727 837471715 860296298 242364554 869648618 30268872 491821963 394777141 20131127 173700158 966670496 229111579 806584006 23804582 105635064 464459088 329321743 63857081 635321423 121653880 132958704 750906565 922490196 947141909 622079908 364404098 7377022...
output:
Yes
result:
ok answer is YES
Test #21:
score: 0
Accepted
time: 1ms
memory: 4072kb
input:
5000 1 134457214 66366743 510695795 647692601 251281150 214852612 164060798 784410357 176612628 257366600 831622406 583714730 788567827 388214278 996017481 370668122 123068077 826727 611250837 764310896 474771771 25258275 472408227 863125009 520565673 612844320 155333773 540293771 636307201 38394910...
output:
No
result:
ok answer is NO
Test #22:
score: 0
Accepted
time: 58ms
memory: 4096kb
input:
5000 5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
Yes
result:
ok answer is YES
Test #23:
score: 0
Accepted
time: 130ms
memory: 4100kb
input:
5000 5000 480846972 610892016 639533817 714913256 707370476 96571926 353958727 831375757 87839310 847270722 827466506 603080568 374255394 649140255 768660763 638287321 670894237 83425137 314931472 283227081 449207650 58600255 399261321 906739148 207833567 58890283 198344474 200802934 944547143 30406...
output:
No
result:
ok answer is NO
Test #24:
score: 0
Accepted
time: 58ms
memory: 4016kb
input:
5000 5000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
Yes
result:
ok answer is YES
Test #25:
score: 0
Accepted
time: 129ms
memory: 4104kb
input:
5000 5000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
output:
No
result:
ok answer is NO