結果
| 問題 |
No.1163 I want to be a high achiever
|
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-08-14 01:16:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,119 bytes |
| コンパイル時間 | 2,025 ms |
| コンパイル使用メモリ | 164,808 KB |
| 実行使用メモリ | 9,728 KB |
| 最終ジャッジ日時 | 2024-10-09 19:43:01 |
| 合計ジャッジ時間 | 3,131 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.08.14 01:16:44
**/
#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;
}
🍮かんプリン