結果

問題 No.1163 I want to be a high achiever
ユーザー simansiman
提出日時 2023-09-05 17:10:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 3,238 ms
コンパイル使用メモリ 104,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 17:10:55
合計ジャッジ時間 3,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  vector<int> B(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  vector<int> C(N);
  int T = 0;
  int c_max = INT_MIN;
  for (int i = 0; i < N; ++i) {
    C[i] = A[i] - X;
    T += C[i];
    c_max = max(c_max, C[i]);
  }

  if (T >= 0) {
    cout << 0 << endl;
  } else if (c_max < 0) {
    cout << -1 << endl;
  } else {
    int L = abs(T);
    vector<ll> dp(L + 1, INT_MAX);
    dp[0] = 0;

    for (int idx = 0; idx < N; ++idx) {
      ll c = C[idx];
      if (c >= 0) continue;

      for (int i = L; i >= 0; --i) {
        ll ni = i + abs(c);
        if (ni > L) ni = L;

        ll n_cost = dp[i] + B[idx];
        dp[ni] = min(dp[ni], n_cost);
      }
    }

    ll ans = INT_MAX;

    for (int i = abs(T); i <= L; ++i) {
      ans = min(ans, dp[i]);
    }

    cout << ans << endl;
  }

  return 0;
}
0