結果

問題 No.1163 I want to be a high achiever
ユーザー rogi52rogi52
提出日時 2022-10-22 13:50:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 957 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 204,848 KB
実行使用メモリ 402,172 KB
最終ジャッジ日時 2023-09-14 08:27:48
合計ジャッジ時間 6,677 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
29,588 KB
testcase_01 AC 150 ms
22,628 KB
testcase_02 AC 146 ms
22,652 KB
testcase_03 AC 151 ms
22,648 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>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,X; cin >> N >> X;
    vector<ll> A(N), B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    ll SUMB = accumulate(B.begin(), B.end(), 0LL);

    ll ans = 1e18;
    int MAX_A = 500 * 100;
    vector<vector<ll>> dp(MAX_A + 1, vector<ll>(N + 1, -1e18));
    dp[0][0] = 0;
    rep(i,N) {
        vector<vector<ll>> nt = dp;
        for(int s = 0; s <= MAX_A; s++)
            for(int k = 0; k <= N; k++)
                if(s + A[i] <= MAX_A && k + 1 <= N) nt[s + A[i]][k + 1] = max(nt[s + A[i]][k + 1], dp[s][k] + B[i]);
        swap(dp, nt);
    }
    for(int n = 1; n <= N; n++) {
        for(int s = n * X; s <= MAX_A; s++) {
            ans = min(ans, SUMB - dp[s][n]);
        }
    }

    cout << (ans == ll(1e18) ? -1 : ans) << endl;
}
0