結果

問題 No.3014 岩井満足性問題
ユーザー applejam
提出日時 2025-01-25 15:28:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 190 ms / 3,000 ms
コード長 1,329 bytes
コンパイル時間 2,964 ms
コンパイル使用メモリ 135,728 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-25 23:46:11
合計ジャッジ時間 3,851 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
#define rep(i, n) for (int i = 0; i< (int)(n); i++) 
ll inf = 4e18;
ll inf2 = 1e14;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, d, k; cin >> n >> d >> k;
    vector<ll> a(n), c(n);
    rep(i, n)cin >> a[i];
    rep(i, n)cin >> c[i];
    vector<vector<ll>> dp(d+1, vector<ll>(k+2, -inf));
    dp[0][0] = 0;
    if(c[0] <= k){
        dp[1][c[0]] = a[0];
    }
    else{dp[1][k+1] = a[0];}
    
    for(int i=1; i<n; i++){
        for(int j = d; j >=0; j--){
            if(j == 0){
                dp[j][0] = 0;
                continue;
            }
            for(int l = k; l>=0; l--){  
                if(l - c[i] >= 0){
                    dp[j][l] = max(dp[j][l], dp[j-1][l-c[i]] + a[i]);
                }
            }

            ll tmp = dp[j][k+1];
            for(int l = k+1; l + c[i] > k; l--){
                tmp = max(tmp, dp[j-1][l] + a[i]);
                if(l == 0)break;
            }
            dp[j][k+1] = tmp;
        }
    }
    ll ans = max(dp[d][k], dp[d][k+1]);
    if(ans > -inf2){
        cout << ans << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}
0