QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214607#7567. Joining Cats0x4F5DA2WA 4ms99428kbC++141.5kb2023-10-14 21:47:072023-10-14 21:47:08

Judging History

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

  • [2023-10-14 21:47:08]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:99428kb
  • [2023-10-14 21:47:07]
  • 提交

answer

#include <cstdio>
#include <algorithm>

const int maxn = 5000;
const int INF = 1000000000;
int n, k;
int w[maxn + 10];
long long suml[maxn + 10];
//long long sumr[maxn + 10];
int s[maxn + 10];
int f[maxn + 10][maxn + 10];

int get_l(int i, int ql){
	int l = ql + 1, r = n;
	while(l != r){
		int mid = (l + r + 1) >> 1;
		if(suml[mid] - suml[ql] <= s[i])
			l = mid;
		else
			r = mid - 1; 
	}
	return l;
}
int get_r(int i, int qr){
	//printf("%d %d\n", i, qr);
	int l = 1, r = qr;
	while(l != r){
		int mid = (l + r) >> 1;
		if(suml[qr - 1] - suml[mid - 1] <= s[i])
			r = mid;
		else
			l = mid + 1; 
	}
	return l;
}

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &w[i]);
		suml[i] = suml[i - 1] + w[i];
	}
	/*for(int i = n; i >= 1; --i){
		sumr[i] = sumr[i + 1] + w[i];
	}*/
	for(int i = 1; i <= k; ++i){
		scanf("%d", &s[i]);
	}
	for(int i = 0; i <= k; ++i){
		for(int j = 0; j <= n; ++j){
			f[i][j] = -INF;
		}
		
	}
	f[0][0] = 0;
	bool flag = false;
	for(int i = 1; i <= k; ++i){
		for(int j = 0; j <= n; ++j){
			f[i][j] = f[i - 1][get_r(i, j + 1) - 1];
			if(f[i - 1][j] >= 0){
				int t = f[i - 1][j] + n + 1 - get_r(i, n + 1 - f[i - 1][j]);
				if(f[i][j] < t)
					f[i][j] = t;
			}
			if(f[i][j] + j >= n - 1){
				flag = true;
				break;
			}
		}
		if(flag)
			break;
	}
	/*for(int i = 1; i <= k; ++i){
		for(int j = 1; j <= n; ++j){
			f[i][j] = f[i - 1][get_r(i, j + 1) - 1];
		}
	}*/
	if(flag)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 4ms
memory: 99428kb

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:

Yes

result:

wrong answer expected NO, found YES