QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204957#7567. Joining Catsucup-team1004#WA 198ms199308kbC++141.8kb2023-10-07 14:28:422023-10-07 14:28:43

Judging History

你现在查看的是最新测评结果

  • [2023-10-07 14:28:43]
  • 评测
  • 测评结果:WA
  • 用时:198ms
  • 内存:199308kb
  • [2023-10-07 14:28:42]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define maxn 5005
#define put() putchar('\n')
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
using namespace std;
void read(int &x){
    int f=1;x=0;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
    x*=f;
}
namespace Debug{
	Tp void _debug(char* f,Ty t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,Ty x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	Tp ostream& operator<<(ostream& os,vector<Ty>& V){os<<"[";for(auto& vv:V) os<<vv<<",";os<<"]";return os;}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
int power(int x,int y=mod-2) {
	int sum=1;
	while (y) {
		if (y&1) sum=sum*x%mod;
		x=x*x%mod;y>>=1;
	}
	return sum;
}
int n,k,w[maxn],s[maxn],d[maxn];
int f[maxn][maxn];
signed main(void){
	int i,j,r;
	read(n);read(k);
	for (i=1;i<=n;i++) read(w[i]);
	for (i=1;i<=k;i++) read(s[i]);
	int id=1;
	for (i=1;i<=n;i++) if (w[id]<w[i]) id=i;
	f[0][id]=id;
	for (i=1;i<=k;i++) {
		int l=id,res=w[id];
		for (j=id;j>=0;j--) {
			res-=w[j];
			while (l>1&&res+w[l-1]<=s[i]) l--,res+=w[l];
//			gdb(i,j,l,res);
			d[l]=max(d[l],f[i-1][j]);
		}
		res=0;l=f[i-1][id],r=f[i-1][id];
		while (r<n&&res+w[r+1]<=s[i]) r++,res+=w[r];
//		gdb(i,r,res);
		for (j=id;j>=1;j--) if (f[i-1][j]>0) {
			while (l>f[i-1][j]) res+=w[l],l--;
			while (res>s[i]) res-=w[r],r--;
			f[i][j]=max(f[i][j],r);
		}
		for (j=1;j<=id;j++) d[j]=max(d[j-1],d[j]);
		for (j=1;j<=id;j++) f[i][j]=max(f[i][j],d[j]),d[j]=0;
//		for (j=1;j<=id;j++) gdb(i,j,f[i][j]);
	}
	puts(f[k][1]>=n?"Yes":"No");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3696kb

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: 3640kb

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: 3624kb

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: 3680kb

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 67ms
memory: 103920kb

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: 130ms
memory: 149072kb

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: 198ms
memory: 199308kb

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: 19ms
memory: 50496kb

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: -100
Wrong Answer
time: 37ms
memory: 59248kb

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:

No

result:

wrong answer expected YES, found NO