結果
問題 | No.1163 I want to be a high achiever |
ユーザー |
![]() |
提出日時 | 2020-09-11 16:19:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,033 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 173,000 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2024-12-26 03:25:42 |
合計ジャッジ時間 | 4,062 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#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;}