QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217154 | #7567. Joining Cats | LiZnB# | WA | 0ms | 3888kb | C++17 | 988b | 2023-10-16 15:58:21 | 2023-10-16 15:58:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5050;
long long a[N],s[N];
bool dfs(int pos,int l,int r){
//printf("%d %d %d\n",pos,l,r);
if(l<=r-1)return true;
if(pos==-1){
return false;
}
long long lsum=0,rsum=0,lpos=l,rpos=r-1;
while(lpos<r){
if(lsum+a[lpos]<=s[pos]){
lsum+=a[lpos];
}else{
lpos--;
break;
}
lpos++;
}
while(rpos>=l){
if(rsum+a[rpos]<=s[pos]){
rsum+=a[rpos];
}else{
rpos++;
break;
}
rpos--;
}
if(lsum<rsum){
return dfs(pos-1,l,rpos);
}else{
return dfs(pos-1,lpos+1,r);
}
}
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)scanf("%lld",&a[i]);
for(int i=0;i<k;i++)scanf("%lld",&s[i]);
bool can=dfs(k-1,0,n);
if(can)printf("Yes\n");
else printf("No\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3888kb
input:
6 7 3 2 1 1 2 3 2 2 2 2 2 2 2
output:
Yes
result:
wrong answer expected NO, found YES