結果
| 問題 | 
                            No.1947 質より種類数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             umezo
                         | 
                    
| 提出日時 | 2022-05-20 22:48:58 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 114 ms / 2,000 ms | 
| コード長 | 641 bytes | 
| コンパイル時間 | 1,842 ms | 
| コンパイル使用メモリ | 195,620 KB | 
| 最終ジャッジ日時 | 2025-01-29 11:14:20 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 37 | 
ソースコード
#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;
}
            
            
            
        
            
umezo