結果

問題 No.3014 岩井満足性問題
ユーザー 回転
提出日時 2025-02-01 18:11:20
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 690 ms / 3,000 ms
コード長 1,036 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 103,400 KB
実行使用メモリ 7,192 KB
最終ジャッジ日時 2025-02-01 18:11:25
合計ジャッジ時間 4,540 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long

signed main() {
    int N, D, K;
    cin >> N >> D >> K;
    
    vector<int> A(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    
    vector<vector<int>> now(D + 1, vector<int>(K + 1, -1e18));
    now[0][0] = 0;
    
    for (int i = 0; i < N; i++) {
        vector<vector<int>> next(D + 1, vector<int>(K + 1, -1e18));
        for (int j = 0; j <= D; j++) {
            for (int k = 0; k <= K; k++) {
                // 選ばない場合
                next[j][k] = max(next[j][k], now[j][k]);
                
                // 選ぶ場合
                if (j + 1 > D) continue;
                next[j + 1][min(k + C[i], K)] = max(next[j + 1][min(k + C[i], K)], now[j][k] + A[i]);
            }
        }
        swap(now, next);
    }
    
    int result = now[D][K];
    if (result < -1e13) cout << "No" << endl;
    else cout << result << endl;
    
    return 0;
}
0