結果
| 問題 |
No.1947 質より種類数
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-05-21 13:51:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,000 bytes |
| コンパイル時間 | 335 ms |
| コンパイル使用メモリ | 42,240 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-20 11:44:18 |
| 合計ジャッジ時間 | 2,194 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 |
ソースコード
/* -*- 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;
}
tnakao0123