結果

問題 No.914 Omiyage
ユーザー Mister
提出日時 2020-04-27 11:10:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 69,256 KB
最終ジャッジ日時 2025-01-10 02:27:01
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>

constexpr int K = 500;

void solve() {
    int n, m, k;
    std::cin >> n >> m >> k;

    std::bitset<K + 1> dp{1};
    auto ndp = dp;

    while (n--) {
        ndp = 0;
        for (int i = 0; i < m; ++i) {
            int a;
            std::cin >> a;
            ndp |= (dp << a);
        }
        std::swap(dp, ndp);
    }

    for (int i = k; i >= 0; --i) {
        if (dp[i]) {
            std::cout << k - i << std::endl;
            return;
        }
    }

    std::cout << -1 << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0