結果
| 問題 | No.2232 Miser's Gift | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2023-05-05 16:15:00 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 817 bytes | 
| コンパイル時間 | 329 ms | 
| コンパイル使用メモリ | 42,056 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-23 01:05:19 | 
| 合計ジャッジ時間 | 4,575 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 55 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 2232.cc:  No.2232 Miser's Gift - yukicoder
 */
#include<cstdio>
#include<algorithm>
 
using namespace std;
/* constant */
const int MAX_N = 100;
const int MAX_W = 100000;
/* typedef */
/* global variables */
int ws[MAX_N], vs[MAX_N], dp[MAX_W + 1];
/* subroutines */
inline void setmax(int &a, int b) { if (a < b) a = b; }
/* main */
int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  for (int i = 0; i < n; i++) scanf("%d%d", ws + i, vs + i);
  fill(dp, dp + w + 1, -1);
  dp[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = w - ws[i]; j >= 0; j--)
      if (dp[j] >= 0)
	setmax(dp[j + ws[i]], dp[j] + vs[i]);
  for (int i = 0; i < w; i++) setmax(dp[i + 1], dp[i]);
  for (int x = 1; x <= w; x++) {
    printf("%d\n", dp[w] - dp[w - x] + 1);
  }
  return 0;
}
            
            
            
        