結果

問題 No.2232 Miser's Gift
ユーザー umimelumimel
提出日時 2023-03-03 21:47:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 1,912 ms
コンパイル使用メモリ 172,060 KB
実行使用メモリ 83,200 KB
最終ジャッジ日時 2024-09-17 22:41:36
合計ジャッジ時間 10,832 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (int i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N, W; cin >> N >> W;
    vector<ll> w(N), v(N); rep(i, N) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    for(ll i=1; i<=N; i++){
        for(ll j=0; j<=W; j++){
            dp[i][j] = dp[i-1][j];
            if(j-w[i-1]>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }

    ll max_v = 0;
    for(ll j=0; j<=W; j++) max_v = max(max_v, dp[N][j]);
    for(ll x=1; x<=W; x++){
        cout << max_v - dp[N][W-x] + 1 << endl;
    }
}
0