QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#261224 | #7567. Joining Cats | fxxx# | ML | 1ms | 7988kb | C++17 | 1.2kb | 2023-11-22 19:14:34 | 2023-11-22 19:14:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define wln putchar('\n')
template<class T1,class T2> void chkmin(T1 &x,T2 y){if(y<x)x=y;}
template<class T1,class T2> void chkmax(T1 &x,T2 y){if(y>x)x=y;}
const int N=5005;
int n,k,a[N],b[N];
int fl[N][N],fr[N][N],f[N][N];
ll sa[N];
int main()
{
scanf("%d%d",&n,&k);
For(i,1,n)scanf("%d",a+i),sa[i]=sa[i-1]+a[i];
For(i,1,k)scanf("%d",b+i);
For(i,1,k)
{
int s=0,p=n;
fr[i][n+1]=n;
Rof(j,n,1)
{
s+=a[j];
while(s>b[i])s-=a[p--];
fr[i][j]=p;
}
s=0; p=1;
fl[i][0]=1;
For(j,1,n)
{
s+=a[j];
while(s>b[i])s-=a[p++];
fl[i][j]=p;
}
}
For(i,1,n)f[0][i]=i;
For(i,0,k-1)
For(j,1,n)
{
chkmax(f[i+1][fl[i+1][j-1]],f[i][j]);
chkmax(f[i+1][j],fr[i+1][f[i][j]+1]);
}
// For(i,1,k)
// For(j,1,n)
// printf("f[%d][%d]=%d\n",i,j,f[i][j]);
if(f[k][1]==n)printf("YES\n");
else printf("NO\n");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7988kb
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: 7916kb
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: 7864kb
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: 1ms
memory: 7868kb
input:
5 1 5 4 3 2 1 10
output:
YES
result:
ok answer is YES
Test #5:
score: -100
Memory Limit Exceeded
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