結果
問題 |
No.1163 I want to be a high achiever
|
ユーザー |
|
提出日時 | 2020-08-12 18:53:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 811 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 77,252 KB |
最終ジャッジ日時 | 2025-01-12 21:30:49 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<numeric> using namespace std; int main(){ 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; }