結果

問題 No.1163 I want to be a high achiever
ユーザー tonegawatonegawa
提出日時 2020-08-12 01:19:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 2,112 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 125,624 KB
実行使用メモリ 200,616 KB
最終ジャッジ日時 2024-04-17 18:14:51
合計ジャッジ時間 7,963 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
12,372 KB
testcase_01 AC 11 ms
12,292 KB
testcase_02 AC 12 ms
12,276 KB
testcase_03 AC 11 ms
12,376 KB
testcase_04 AC 201 ms
200,348 KB
testcase_05 AC 205 ms
200,548 KB
testcase_06 AC 208 ms
200,408 KB
testcase_07 AC 210 ms
200,568 KB
testcase_08 AC 219 ms
200,364 KB
testcase_09 AC 202 ms
200,184 KB
testcase_10 AC 211 ms
200,424 KB
testcase_11 AC 208 ms
200,456 KB
testcase_12 AC 208 ms
200,556 KB
testcase_13 AC 205 ms
200,248 KB
testcase_14 AC 204 ms
200,340 KB
testcase_15 AC 210 ms
200,472 KB
testcase_16 AC 200 ms
200,528 KB
testcase_17 AC 202 ms
200,516 KB
testcase_18 AC 205 ms
200,568 KB
testcase_19 AC 198 ms
200,268 KB
testcase_20 AC 197 ms
200,268 KB
testcase_21 AC 195 ms
200,136 KB
testcase_22 AC 205 ms
200,508 KB
testcase_23 AC 202 ms
200,616 KB
testcase_24 AC 211 ms
200,488 KB
testcase_25 AC 202 ms
200,240 KB
testcase_26 AC 151 ms
199,832 KB
testcase_27 AC 9 ms
12,368 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 233 ms
199,932 KB
testcase_30 AC 5 ms
5,732 KB
testcase_31 AC 5 ms
6,092 KB
testcase_32 AC 7 ms
7,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, x;std::cin >> n >> x;
  vll a(n), b(n);
  re(i, n) scanf("%lld", &a[i]);
  re(i, n) scanf("%lld", &b[i]);

  vvl minus, plus;
  for(int i=0;i<n;i++){
    a[i]-=x;
    if(a[i]<0) minus.push_back({abs(a[i]), b[i]});
    else plus.push_back({a[i], b[i]});
  }

  //kを作るのに必要なお金
  ll m = minus.size();
  ll p = plus.size();
  ll INF = 10000000000;
  vvl dp = VV(m+1, 50001, INF, ll);
  vvl dp2 = VV(p+1, 50001, INF, ll);

  if(m==0){
    std::cout << 0 << '\n';
    return 0;
  }

  dp[0][0] = 0;
  if(p!=0) dp2[0][0] = 0;

  for(int i=0;i<m;i++){
    ll val = minus[i][0], w = minus[i][1];
    for(int j=0;j<50001;j++){
      //スルー
      dp[i+1][j] = min(dp[i+1][j], dp[i][j] + w);
      //取る
      if(j+val<=50000) dp[i+1][j+val] = min(dp[i+1][j+val], dp[i][j]);
    }
  }

  for(int i=0;i<p;i++){
    ll val = plus[i][0], w = plus[i][1];
    for(int j=0;j<50001;j++){
      //スルー
      dp2[i+1][j] = min(dp2[i+1][j], dp2[i][j] + w);
      //取る
      if(j+val<=50000) dp2[i+1][j+val] = min(dp2[i+1][j+val], dp2[i][j]);
    }
  }
  for(int i=1;i<=50000;i++) dp[m][i] = min(dp[m][i], dp[m][i-1]);
  for(int i=50000-1;i>=0;i--) dp2[p][i] = min(dp2[p][i], dp2[p][i+1]);

  //for(int i=0;i<=10;i++) std::cout << dp2[p][i] << (i==10?"\n":" ");
  //for(int i=0;i<=10;i++) std::cout << dp[m][i] << (i==10?"\n":" ");

  ll ans = INF;
  for(int i=0;i<=50000;i++){
    ans = min(ans, dp2[p][i] + dp[m][i]);
  }
  std::cout << (ans==INF?-1:ans) << '\n';
  return 0;
}
0