QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#263162#7567. Joining CatsDateTree#WA 0ms3676kbC++171.1kb2023-11-24 16:15:502023-11-24 16:15:51

Judging History

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

  • [2023-11-24 16:15:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2023-11-24 16:15:50]
  • 提交

answer

#include <bits/stdc++.h>

const int N = 5005;

int n, k;
int w[N], s[N];

bool work(int l, int r, int t) {
    //printf("%d %d %d\n", l, r, t);
    if (l == r)
        return 1;
    if (t > k)
        return 0;
    int suml = 0, sumr = 0;
    int tl = l - 1, tr = r + 1;
    for (tl = l; tl <= r; ++tl) {
        if (suml + w[tl] > s[t])
            break;
        suml += w[tl];
    }
    if (tl > r)
        return 1;
    for (tr = r; tr >= l; --tr) {
        if (sumr + w[tr] > s[t])
            break;
        sumr += w[tr];
    }
    if (tr < l)
        return 1;
    if (suml <= sumr)
        return work(tl, r, t + 1);
    else
        return work(l, tr, t + 1);
}

int main() {
    std::cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        std::cin >> w[i];
    for (int i = 1; i <= k; ++i)
        std::cin >> s[i];
    std::sort(s + 1, s + 1 + k);
    std::reverse(s + 1, s + 1 + k);
    int ans = work(1, n, 1);
    if (ans) {
        std::cout << "Yes\n";
    } else {
        std::cout << "No\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

7 4
1 2 3 4 3 2 1
3 3 3 3

output:

No

result:

wrong answer expected YES, found NO