QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692838#5303. No Bug No GameCalculatelove#RE 0ms0kbC++141.2kb2024-10-31 15:06:532024-10-31 15:07:03

Judging History

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

  • [2024-10-31 15:07:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-31 15:06:53]
  • 提交

answer

#include <bits/stdc++.h>

typedef long long s64;

const int N = 3010;

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

int f[20][N];

int ans;
void solve(int l, int r, int dep) {
    if (l == r) {
        for (int i = std::max(0, k - p[l]); i < k; i ++)
            ans = std::max(ans, f[dep][i] + w[l][k - i]);
        return;
    }

    int mid = (l + r) >> 1;

    for (int i = 0; i <= k; i ++) f[dep + 1][i] = f[dep][i];
    for (int x = mid + 1; x <= r; x ++)
        for (int i = k; i >= p[x]; i --)
            f[dep + 1][i] = std::max(f[dep + 1][i], f[dep + 1][i - p[x]] + w[x][p[x]]);
    
    solve(l, mid, dep + 1);

    for (int i = 0; i <= k; i ++) f[dep + 1][i] = f[dep][i];
    for (int x = l; x <= mid; x ++)
        for (int i = k; i >= p[x]; i --)
            f[dep + 1][i] = std::max(f[dep + 1][i], f[dep + 1][i - p[x]] + w[x][p[x]]);

    solve(mid + 1, r, dep + 1);
}

int main() {
    freopen("C.in", "r", stdin);

    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; i ++) {
        scanf("%d", &p[i]);
        for (int j = 1; j <= p[i]; j ++) scanf("%d", &w[i][j]);
    }

    f[0][0] = 0;
    for (int i = 1; i <= k; i ++) f[0][i] = -0x3f3f3f3f;

    solve(1, n, 0);

    printf("%d\n", ans);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:


result: