結果

問題 No.3014 岩井満足性問題
ユーザー t98slider
提出日時 2025-01-25 13:02:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 143 ms / 3,000 ms
コード長 1,139 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 199,812 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-25 22:31:03
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d, k;
    cin >> n >> d >> k;
    vector<pair<int,int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].first;
    for(int i = 0; i < n; i++) cin >> a[i].second;
    vector<vector<ll>> dp(d + 1, vector<ll>(k + 1, -(1ll << 62)));
    dp[0][0] = 0;
    int cur = 0;
    for(auto [v, v2] : a){
        for(int i = min(cur, d - 1); i >= 0; i--){
            for(int j = k; j >= 0; j--){
                int nj = min(k, j + v2);
                dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + v);
            }
        }
        cur++;
    }
    ll ans = dp[d][k];
    if(ans < -(1ll << 30) * n){
        cout << "No\n";
        return 0;
    }
    cout << ans << '\n';
}
0