QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217154#7567. Joining CatsLiZnB#WA 0ms3888kbC++17988b2023-10-16 15:58:212023-10-16 15:58:22

Judging History

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

  • [2023-10-16 15:58:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3888kb
  • [2023-10-16 15:58:21]
  • 提交

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