QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600554#5005. Geekflix333zhanWA 6ms4336kbC++202.2kb2024-09-29 17:18:362024-09-29 17:18:36

Judging History

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

  • [2024-09-29 17:18:36]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4336kb
  • [2024-09-29 17:18:36]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve () {
    int n, m;
    cin >> n >> m;

    vector <int> a (n + 1);
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    vector <int> b (n + 1);
    for (int i = 1; i <= n; i ++) {
        cin >> b[i];
    }
    vector <vector<int>> dp1 (n+1,vector<int>(m + 1));
    vector <vector<int>> dp2 (n+1,vector<int>(m + 1));

    auto work = [&] ()->vector<vector<int>> {
        vector <vector<int>> dp (n+1,vector<int>(m + 1,0));

        dp[1][1] = 0;

        int maxx = 0;
        for (int i = 1; i <= n; i ++) {
            // auto ndp = dp;
            for (int j = 1; j <= m; j ++) {
                dp[i][j] = dp[i-1][j - 1];
            }
            for (int j = 1; j <= m; j ++) {
                for (int k = 1; a[i] - (k - 1) * b[i] > 0 && k + (i > 1) <= j; k ++) {
                    dp[i][j] = max (dp[i][j], dp[i-1][j - k - (i > 1)] + k * a[i] - k * (k - 1) / 2 * b[i]);
                }
            }

            // dp = move (ndp);
            // maxx = max (maxx, *max_element (dp.begin (), dp.end ()));
        }

        return dp;
    };

    dp1= work ();
    
    reverse (a.begin () + 1, a.end ());
    reverse (b.begin () + 1, b.end ());

    dp2=work();
    // cout<<dp2[1][1]<<endl;;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp2[i][j]=max(dp2[i][j],dp2[i][j-1]);
            dp1[i][j]=max(dp1[i][j],dp1[i][j-1]);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m;j++){
            int maxx1=0,maxx2=0;
            for(int k=1;k<=n-i;k++){
                if(m-i-j>0)
                    maxx1=max(maxx1,dp2[k][m-i-j]);
            }
            for(int k=1;k<=i;k++){
                maxx2=max(maxx2,dp1[k][j]);
            }
            ans=max(ans,maxx1+maxx2);

            // if(i==2)
            // cerr<<dp1[i][j]<<" "<<(m-i-j>0)*dp2[n-i][m-i-j]<<endl;
        }
    }

    cout << ans << '\n';
}

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

    int T = 1;
    // cin >> T;

    while (T --) {
        solve ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 10
10 10 10
5 3 1

output:

67

result:

ok single line: '67'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

5 10
1 2 3 4 5
0 1 2 3 4

output:

16

result:

ok single line: '16'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

5 5
1 5000 1 1 5000
1 3000 1 1 3000

output:

10000

result:

ok single line: '10000'

Test #4:

score: -100
Wrong Answer
time: 6ms
memory: 4336kb

input:

100 500
1676 3766 611 4073 4277 633 1921 650 4074 4382 1027 1849 861 1199 1411 21 2021 2227 1829 2487 1415 4006 3680 2374 2332 1461 4384 3874 3053 2968 1347 4728 3085 3309 3800 2362 3941 2072 3011 4366 1454 4038 1214 3666 236 2624 38 3608 1202 1866 1094 2616 2223 4774 4989 4554 2586 724 3428 1990 43...

output:

824005

result:

wrong answer 1st lines differ - expected: '824766', found: '824005'