結果

問題 No.617 Nafmo、買い出しに行く
ユーザー guriceringuricerin
提出日時 2019-03-27 22:32:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 1,450 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 102,356 KB
実行使用メモリ 487,592 KB
最終ジャッジ日時 2024-04-19 13:47:49
合計ジャッジ時間 3,360 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,824 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 46 ms
65,288 KB
testcase_03 AC 85 ms
146,816 KB
testcase_04 AC 14 ms
19,456 KB
testcase_05 AC 134 ms
250,112 KB
testcase_06 AC 258 ms
487,592 KB
testcase_07 AC 252 ms
487,516 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 180 ms
348,800 KB
testcase_11 AC 214 ms
421,120 KB
testcase_12 AC 127 ms
226,396 KB
testcase_13 AC 89 ms
136,476 KB
testcase_14 AC 104 ms
179,328 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P       = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> ws(n);
    for (auto &w : ws) {
        cin >> w;
    }

    vector<vector<int>> dp(n + 10, vector<int>(k + 10, 0));
    rep(i, 0, n) {
        rep(sum_w, 0, k + 1) {
            int w = ws[i];
            // i番目の商品を選ぶ場合
            if (sum_w - w >= 0) {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - w] + w);
            }

            // i番目の商品を選ばない場合
            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[n][k] << endl;
}
0