結果

問題 No.1163 I want to be a high achiever
ユーザー face4
提出日時 2020-08-12 18:56:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 77,152 KB
最終ジャッジ日時 2025-01-12 21:30:55
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, x;
    cin >> n >> x;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++)  cin >> a[i], a[i] -= x;
    for(int i = 0; i < n; i++)  cin >> b[i];
    if(*max_element(a.begin(),a.end()) < 0){
        cout << -1 << endl;
        return 0;
    }else if(accumulate(a.begin(), a.end(), 0) >= 0){
        cout << 0 << endl;
        return 0;
    }
    int k = -accumulate(a.begin(), a.end(), 0);
    vector<int> dp(k+100, 1<<30);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= 0)   continue;
        for(int j = k+99; j >= -a[i]; j--){
            dp[j] = min(dp[j], dp[j+a[i]]+b[i]);
        }
    }
    cout << *min_element(dp.begin()+k, dp.end()) << endl;
    return 0;
}
0