結果

問題 No.2093 Shio Ramen
ユーザー umezo
提出日時 2022-10-07 22:25:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 194,728 KB
最終ジャッジ日時 2025-02-07 23:34:28
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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;

int dp[1010][1010];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  rep(i,1010) rep(j,1010) dp[i][j]=-1;
  
  int n,I;
  cin>>n>>I;
  vector<int> S(n),A(n);
  rep(i,n) cin>>S[i]>>A[i];
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=I;j++){
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      if(j+S[i]<=I) dp[i+1][j+S[i]]=max(dp[i+1][j+S[i]],dp[i][j]+A[i]);
    }
  }
  int ma=0;
  for(int j=0;j<=I;j++){
    ma=max(ma,dp[n][j]);
  }
  cout<<ma<<endl;
  
  return 0;
}
0