結果

問題 No.3076 Goodstuff Deck Builder
ユーザー tnakao0123
提出日時 2025-04-14 16:01:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 94 ms / 3,000 ms
コード長 1,217 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 68,128 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-14 16:01:13
合計ジャッジ時間 4,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%d%d", &ci, &di);
      |     ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3076.cc:  No.3076 Goodstuff Deck Builder - yukicoder
 */

#include<cstdio>
#include<algorithm>
#include<functional>
#include<utility>

using namespace std;

/* constant */

const int MAX_N = 10000;
const int MAX_M = 1000;
const int D = 10;

/* typedef */

using ll = long long;
using pii = pair<int,int>;

/* global variables */

pii ps[MAX_N];
ll dp[D + 1][MAX_M + 1];

/* subroutines */

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

/* main */

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

  ll s0 = 0;
  int k = 0;
  for (int i = 0; i < n; i++) {
    int ci, di;
    scanf("%d%d", &ci, &di);
    if (ci == 0) s0 += di;
    else ps[k++] = {ci, di};
  }
  sort(ps, ps + k, greater<pii>());
  n = k;

  for (int i = 0; i <= D; i++) fill(dp[i], dp[i] + m + 1, -1);
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    auto [ci, di] = ps[i];
    for (int j = D - 1; j >= 0; j--)
      for (int k = m - 1; k >= 0; k--)
	if (dp[j][k] >= 0) {
	  int k1 = k + (ci << j);
	  if (k1 <= m) setmax(dp[j + 1][k1], dp[j][k] + di);
	}
  }

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

  printf("%lld\n", s0 + maxd);

  return 0;
}
0