結果

問題 No.1163 I want to be a high achiever
ユーザー けーむけーむ
提出日時 2020-08-17 14:00:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 176,248 KB
実行使用メモリ 367,008 KB
最終ジャッジ日時 2024-04-19 21:07:38
合計ジャッジ時間 12,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,884 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1,962 ms
245,248 KB
testcase_05 TLE -
testcase_06 AC 1,456 ms
203,904 KB
testcase_07 TLE -
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;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n), b(n);
    ll cnt = 0;
    rep(i, n) {
        cin >> a[i];
        a[i] -= x;
        if (a[i] >= 0) cnt++;
    }
    rep(i, n) cin >> b[i];
    if (cnt == 0) {
        cout << -1 << endl;
        return 0;
    }
    vector<map<ll, ll>> dp(n + 1);
    dp[0][0] = 0;
    rep(i, n) {
        for(auto &x : dp[i]) {
            if (dp[i + 1].count(x.first) == 0) {
                dp[i + 1][x.first] = x.second + b[i];
            }
            else {
                dp[i + 1][x.first] = min(dp[i + 1][x.first], x.second + b[i]);
            }
            if (dp[i + 1].count(x.first + a[i]) == 0) {
                dp[i + 1][x.first + a[i]] = x.second;
            }
            else {
                dp[i + 1][x.first + a[i]] = min(dp[i + 1][x.first + a[i]], x.second);
            }
        }
    }
    ll ans = LONG_LONG_MAX;
    for(auto &x : dp[n]) {
        if (x.first < 0) continue;
        ans = min(ans, x.second);
    }
    cout << ans << endl;
    return 0;
}
0