結果

問題 No.1163 I want to be a high achiever
ユーザー msm1993msm1993
提出日時 2020-09-11 16:19:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 170,744 KB
実行使用メモリ 9,676 KB
最終ジャッジ日時 2023-08-26 23:38:59
合計ジャッジ時間 3,891 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 5 ms
5,212 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 8 ms
8,000 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 9 ms
9,676 KB
testcase_10 AC 5 ms
5,516 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 4 ms
5,092 KB
testcase_13 AC 7 ms
7,604 KB
testcase_14 AC 8 ms
7,800 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 6 ms
6,416 KB
testcase_17 AC 4 ms
5,000 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 8 ms
7,788 KB
testcase_20 AC 9 ms
8,840 KB
testcase_21 AC 10 ms
9,632 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,788 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 6 ms
6,328 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n,x;cin >> n >> x;
    vector<int> a(n),b(n),c,d;
    int total = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= x;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (a[i] < 0) {
            c.push_back(-a[i]);
            d.push_back(b[i]);
        }
        else {
            total += a[i];
        }
    }
    int INF = 1e9 + 6;
    
    vector<vector<int>> dp(c.size()+1,vector<int>(total+1,INF));
    dp[0][0] = 0;
    for (int i = 0; i < c.size(); i++) {
        for (int j = 0; j <= total; j++) {
            if (dp[i][j] != INF) dp[i + 1][j] = dp[i][j] + d[i];
            if (j-c[i] >= 0) dp[i + 1][j] = min(dp[i+1][j],dp[i][j-c[i]]);
        }
    }
    int ans = INF;
    for (int i = 0; i <= total; i++) {
        ans = min(ans,dp[c.size()][i]);
    }
    if (ans == INF || c.size() == n) {
        puts("-1");
    }
    else {
        cout << ans << endl;
    }
    return 0;
}
0