結果

問題 No.1947 質より種類数
ユーザー umezoumezo
提出日時 2022-05-20 22:48:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 204,124 KB
実行使用メモリ 202,948 KB
最終ジャッジ日時 2023-10-20 13:38:51
合計ジャッジ時間 4,636 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,644 KB
testcase_01 AC 2 ms
5,640 KB
testcase_02 AC 2 ms
5,640 KB
testcase_03 AC 3 ms
5,632 KB
testcase_04 AC 3 ms
8,312 KB
testcase_05 AC 3 ms
8,312 KB
testcase_06 AC 3 ms
8,256 KB
testcase_07 AC 3 ms
8,312 KB
testcase_08 AC 3 ms
8,284 KB
testcase_09 AC 5 ms
10,360 KB
testcase_10 AC 4 ms
10,360 KB
testcase_11 AC 8 ms
16,504 KB
testcase_12 AC 7 ms
14,456 KB
testcase_13 AC 4 ms
8,312 KB
testcase_14 AC 34 ms
60,692 KB
testcase_15 AC 17 ms
31,468 KB
testcase_16 AC 45 ms
86,028 KB
testcase_17 AC 56 ms
110,068 KB
testcase_18 AC 134 ms
192,476 KB
testcase_19 AC 111 ms
168,680 KB
testcase_20 AC 72 ms
127,868 KB
testcase_21 AC 94 ms
150,008 KB
testcase_22 AC 7 ms
14,456 KB
testcase_23 AC 36 ms
70,044 KB
testcase_24 AC 3 ms
8,312 KB
testcase_25 AC 3 ms
8,312 KB
testcase_26 AC 3 ms
6,104 KB
testcase_27 AC 3 ms
8,312 KB
testcase_28 AC 3 ms
8,312 KB
testcase_29 AC 186 ms
202,948 KB
testcase_30 AC 126 ms
202,948 KB
testcase_31 AC 2 ms
5,632 KB
testcase_32 AC 2 ms
5,632 KB
testcase_33 AC 2 ms
5,708 KB
testcase_34 AC 74 ms
202,948 KB
testcase_35 AC 74 ms
202,948 KB
testcase_36 AC 150 ms
202,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

ll dp[5050][5050];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,v,c;
  cin>>n>>v>>c;
  vector<ll> V(n+1),W(n+1);
  rep(i,n) cin>>V[i+1]>>W[i+1];
  
  for(int i=1;i<=n;i++){
    for(int j=v;j>=0;j--){
      dp[i][j]=dp[i-1][j];
      if(j+V[i]<=v) dp[i][j]=max(dp[i][j],dp[i-1][j+V[i]]+W[i]+c);
      if(j+V[i]<=v) dp[i][j]=max(dp[i][j],dp[i][j+V[i]]+W[i]);
    }
  }
  ll ans=0;
  for(int j=0;j<=v;j++) ans=max(ans,dp[n][j]);
  cout<<ans<<endl;

  return 0;
}
0