結果

問題 No.1858 Gorgeous Knapsack
ユーザー erbowlerbowl
提出日時 2022-07-24 15:11:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 209,768 KB
実行使用メモリ 198,640 KB
最終ジャッジ日時 2023-09-20 14:30:23
合計ジャッジ時間 6,039 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 3 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 190 ms
198,636 KB
testcase_35 AC 172 ms
198,640 KB
testcase_36 AC 187 ms
198,588 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 172 ms
198,624 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+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