結果

問題 No.1947 質より種類数
ユーザー tnakao0123tnakao0123
提出日時 2022-05-21 02:18:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 993 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 43,184 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-20 15:28:50
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 17 ms
4,348 KB
testcase_05 AC 16 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 24 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 12 ms
4,348 KB
testcase_11 AC 37 ms
4,348 KB
testcase_12 AC 24 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 54 ms
4,348 KB
testcase_15 AC 30 ms
4,348 KB
testcase_16 AC 85 ms
4,348 KB
testcase_17 AC 103 ms
4,348 KB
testcase_18 AC 188 ms
4,348 KB
testcase_19 AC 168 ms
4,348 KB
testcase_20 AC 126 ms
4,348 KB
testcase_21 AC 145 ms
4,348 KB
testcase_22 AC 9 ms
4,348 KB
testcase_23 AC 66 ms
4,348 KB
testcase_24 AC 61 ms
4,348 KB
testcase_25 AC 50 ms
4,348 KB
testcase_26 AC 24 ms
4,348 KB
testcase_27 AC 33 ms
4,348 KB
testcase_28 AC 48 ms
4,348 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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 */

ll dp[2][MAX_V + 1];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n, v, c;
  scanf("%d%d%d", &n, &v, &c);

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

  for (int i = 0; i < n; i++) {
    int vi, wi;
    scanf("%d%d", &vi, &wi);

    copy(dp[cur], dp[cur] + v + 1, dp[nxt]);

    int kv = vi, kw = c + wi;
    while (kv <= v) {
      int maxj = v - kv;
      for (int j = 0; j <= maxj; j++)
	if (dp[cur][j] >= 0)
	  setmax(dp[nxt][j + kv], dp[cur][j] + kw);
      kv += vi, kw += wi;
    }

    swap(cur, nxt);
  }

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

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