結果

問題 No.1947 質より種類数
ユーザー tnakao0123tnakao0123
提出日時 2022-05-21 13:51:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 42,480 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 16:10:57
合計ジャッジ時間 2,401 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 29 ms
4,348 KB
testcase_15 AC 16 ms
4,348 KB
testcase_16 AC 40 ms
4,348 KB
testcase_17 AC 51 ms
4,348 KB
testcase_18 AC 90 ms
4,348 KB
testcase_19 AC 78 ms
4,348 KB
testcase_20 AC 60 ms
4,348 KB
testcase_21 AC 70 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 33 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 88 ms
4,348 KB
testcase_30 AC 88 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 31 ms
4,348 KB
testcase_35 AC 24 ms
4,348 KB
testcase_36 AC 88 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1947.cc:  No.1947 質より種類数 - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 5000;
const int MAX_V = 5000;

/* typedef */

typedef long long ll;

/* global variables */

int vs[MAX_N], ws[MAX_N];
ll dp[MAX_V + 1];

/* subroutines */

template <typename T>
inline void setmax(T &a, T b) { if (a < b) a = b; }

/* main */

int main() {
  int n, v, c;
  scanf("%d%d%d", &n, &v, &c);
  for (int i = 0; i < n; i++) scanf("%d%d", vs + i, ws + i);

  fill(dp, dp + v + 1, -1);
  dp[0] = 0;

  for (int i = 0; i < n; i++) {
    int w = c + ws[i];
    for (int j = v - vs[i]; j >= 0; j--)
      if (dp[j] >= 0)
	setmax(dp[j + vs[i]], dp[j] + w);
  }

  for (int j = 0; j <= v; j++)
    for (int i = 0; i < n; i++)
      if (j >= vs[i] && dp[j - vs[i]] >= 0)
	setmax(dp[j], dp[j - vs[i]] + ws[i]);

  ll maxd = 0;
  for (int j = 0; j <= v; j++) setmax(maxd, dp[j]);

  printf("%lld\n", maxd);
  return 0;
}
0