QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205033#7567. Joining Catsucup-team1469#WA 126ms3892kbC++202.2kb2023-10-07 14:40:322023-10-07 14:40:33

Judging History

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

  • [2023-10-07 14:40:33]
  • 评测
  • 测评结果:WA
  • 用时:126ms
  • 内存:3892kb
  • [2023-10-07 14:40:32]
  • 提交

answer

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tag_and_trait.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// namespace gt = __gnu_pbds;
#define IS_MULTITEST 0

using namespace std;

// #include "angel/math/modint.hpp"

#pragma region Macros
// clang-format off
using ll = long long; using uint = unsigned int; using ull = unsigned long long;
using i32 = int; using i64 = ll; using u32 = uint; using u64 = ull;
template <class T> using Vec = vector<T>;
template <class T> using RevPriq = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf32 = 1 << 30; constexpr ll inf64 = 1ll << 60;
constexpr char eoln = '\n';
#define L(i, l, r) for (int i = l; i < r; ++i)
#define R(i, l, r) for (int i = r - 1; i >= l; --i)
#define ALL(x) (x).begin(), (x).end()
#define mem(a, x) memset(a, x, sizeof(a))
#define sz(a) (int)((a).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
// clang-format on
#pragma endregion

// Coding Space

// vars
constexpr int MaxN = 5010, MaxK = 5010;
int N, K;
ll W[MaxN], S[MaxK];

// funcs

void main_() {
    cin >> N >> K;
    L(i, 0, N) cin >> W[i];
    L(i, 0, K) cin >> S[i];

    Vec<int> dp(N, 0);
    L(i, 0, N) dp[i] = i + 1;

    L(i, 0, K) {
        int p1 = 0, p2 = 0;
        ll sum1 = 0, sum2 = 0;
        auto ndp = dp;
        L(r, 0, N) {
            ndp[p1] = max(ndp[p1], dp[r]);
            sum1 += W[r];
            while (sum1 > S[i]) {
                sum1 -= W[p1++];
            }
        }
        L(r, 0, N) {
            L(j, (r == 0 ? 0 : dp[r - 1]), dp[r]) {
                sum2 -= W[j];
            }
            while (p2 != N and sum2 + W[p2] <= S[i]) {
                sum2 += W[p2++];
            }
            ndp[r] = max(ndp[r], p2);
        }
        dp = move(ndp);
    }

    const auto x = dp[0];
    cout << (x == N ? "Yes" : "No") << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if constexpr (IS_MULTITEST == 0) {
        main_();
    } else {
        // multitest (cf-style)
        int T;
        cin >> T;
        while (T--) {
            main_();
            cout << flush;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 126ms
memory: 3704kb

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