結果

問題 No.1163 I want to be a high achiever
ユーザー けーむけーむ
提出日時 2020-08-17 13:57:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,600 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 175,372 KB
実行使用メモリ 204,544 KB
最終ジャッジ日時 2024-04-19 18:49:03
合計ジャッジ時間 5,881 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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);
    rep(i, n) {
        cin >> a[i];
        a[i] -= x;
    }
    if (accumulate(all(a), 0LL) < 0) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, n) cin >> b[i];
    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