結果

問題 No.1163 I want to be a high achiever
ユーザー sten_sansten_san
提出日時 2021-01-27 12:49:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,600 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 211,648 KB
実行使用メモリ 211,732 KB
最終ジャッジ日時 2023-09-06 16:51:54
合計ジャッジ時間 6,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct uns_t {} uns;
template <typename Element, typename Head, typename ...Args>
auto vec(Element init, Head arg, Args ...args) {
    if constexpr (sizeof...(Args) == 0) return std::vector(arg, init);
    else return std::vector(arg, vec(init, args...));
}
template <typename Element, typename Head, typename ...Args>
auto vec(uns_t, Head arg, Args ...args) {
    return vec(Element(), arg, args...);
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main() {
    constexpr int64_t inf = INT64_MAX / 4;

    int n, x; cin >> n >> x;
    auto a = vec<int>(uns, n);
    auto b = vec<int>(uns, n);
    for (auto &e : a) cin >> e;
    for (auto &e : b) cin >> e;
    int sum = accumulate(begin(a), end(a), 0);

    auto dp1 = vec(-inf, n + 1, sum + 1);
    auto dp2 = vec(-inf, n + 1, sum + 1);
    dp2[0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= sum; ++k) {
                dp1[j][k] = dp2[j][k];
            }
        }

        for (int j = 1; j <= n; ++j) {
            for (int k = 0; k <= sum; ++k) {
                dp1[j][k] = max(dp1[j][k], dp2[j - 1][max(0, k - a[i])] + b[i]);
            }
        }

        swap(dp1, dp2);
    }

    int64_t ans = inf, all = accumulate(begin(b), end(b), 0);
    for (int i = 1; i <= n; ++i) {
        if (sum < x * i) continue;
        ans = min(ans, all - dp2[i][x * i]);
    }

    if (ans != inf) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
}

0