結果

問題 No.3401 Large Knapsack Problem
コンテスト
ユーザー t98slider
提出日時 2025-12-08 00:22:44
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 593 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,675 ms
コンパイル使用メモリ 195,488 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-08 00:22:49
合計ジャッジ時間 4,247 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr int r = 1'000'000;
    int n, W;
    cin >> n >> W;
    vector<int> dp(r + 1);
    for(int i = 0; i < n; i++){
        int v, w;
        cin >> v >> w;
        for(int j = 0; j + w <= r; j++){
            dp[j + w] = max(dp[j + w], dp[j] + v);
        }
    }
    ll ans = 0;
    for(int i = 1; i <= W && i <= r; i++){
        int d = W / i;
        int r = W - d * i;
        ans = max(ans, (ll)(dp[i]) * d + dp[r]);
    }
    cout << ans << '\n';
}
0