QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600436#5000. Balanced Seesaw ArraySound_MediumWA 0ms3624kbC++231.9kb2024-09-29 16:33:532024-09-29 16:33:53

Judging History

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

  • [2024-09-29 16:33:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-09-29 16:33:53]
  • 提交

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] = a[1];

        int maxx = 0;
        for (int i = 1; i <= n; i ++) {
            // auto ndp = dp;
            for (int j = 2; 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 + 1 <= j; k ++) {
                    dp[i][j] = max (dp[i][j], dp[i-1][j - k - 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++){
            int maxx=0;
            for(int k=1;k<=n-i;k++){
                if(m-i-j>0)
                    maxx=max(maxx,dp2[k][m-i-j]);
            }
            ans=max(ans,dp1[i][j]+maxx);
            // 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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3624kb

input:

3 6
1 2 3
3 1 1
3 1 3
1 1 1 2
3 1 3
2 2 2 0
3 2 3

output:

8

result:

wrong answer 1st lines differ - expected: 'Yes', found: '8'