結果

問題 No.1858 Gorgeous Knapsack
ユーザー erbowlerbowl
提出日時 2022-07-24 15:15:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 210,120 KB
実行使用メモリ 198,724 KB
最終ジャッジ日時 2023-09-20 14:34:36
合計ジャッジ時間 5,343 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 42 ms
40,404 KB
testcase_05 AC 10 ms
10,324 KB
testcase_06 AC 51 ms
48,808 KB
testcase_07 AC 30 ms
28,956 KB
testcase_08 AC 72 ms
69,348 KB
testcase_09 AC 123 ms
117,024 KB
testcase_10 AC 34 ms
31,648 KB
testcase_11 AC 58 ms
54,612 KB
testcase_12 AC 96 ms
91,352 KB
testcase_13 AC 10 ms
8,232 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 17 ms
17,712 KB
testcase_25 AC 86 ms
85,004 KB
testcase_26 AC 71 ms
68,628 KB
testcase_27 AC 69 ms
66,024 KB
testcase_28 AC 46 ms
45,880 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 210 ms
198,704 KB
testcase_35 AC 186 ms
198,496 KB
testcase_36 AC 209 ms
198,724 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 187 ms
198,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll n,m;
    std::cin >> n>>m;
    vector<pair<ll,ll>> vw(n);
    for (int i = 0; i < n; i++) {
        std::cin >> vw[i].first >> vw[i].second;
    }
    sort(vw.rbegin(),vw.rend());
    vector<vector<ll>> dp(n+1, vector<ll>(m+1,-1));
    ll ans = 0;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i+1][j] = dp[i][j];
            
            if(j-vw[i].second>=0&&dp[i][j-vw[i].second]>=0){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-vw[i].second]+vw[i].first);
                ans = max(ans, dp[i+1][j]*vw[i].first);
            }
        }
    }
    std::cout << ans << std::endl;
}
0