結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
12,376 KB
testcase_01 AC 12 ms
12,296 KB
testcase_02 AC 13 ms
12,396 KB
testcase_03 AC 13 ms
12,340 KB
testcase_04 AC 239 ms
200,516 KB
testcase_05 AC 235 ms
200,580 KB
testcase_06 AC 231 ms
200,428 KB
testcase_07 AC 237 ms
200,572 KB
testcase_08 AC 237 ms
200,644 KB
testcase_09 AC 229 ms
200,232 KB
testcase_10 AC 233 ms
200,560 KB
testcase_11 AC 233 ms
200,512 KB
testcase_12 AC 234 ms
200,592 KB
testcase_13 AC 235 ms
200,440 KB
testcase_14 AC 235 ms
200,480 KB
testcase_15 AC 238 ms
200,648 KB
testcase_16 AC 237 ms
200,308 KB
testcase_17 AC 238 ms
200,448 KB
testcase_18 AC 240 ms
200,712 KB
testcase_19 AC 238 ms
200,432 KB
testcase_20 AC 239 ms
200,308 KB
testcase_21 AC 232 ms
200,176 KB
testcase_22 AC 240 ms
200,412 KB
testcase_23 AC 237 ms
200,400 KB
testcase_24 AC 236 ms
200,536 KB
testcase_25 AC 233 ms
200,396 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 5 ms
5,728 KB
testcase_31 WA -
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)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