結果

問題 No.1947 質より種類数
ユーザー RVindicatio
提出日時 2022-05-20 22:01:34
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 10,623 ms
コンパイル使用メモリ 282,392 KB
最終ジャッジ日時 2025-01-29 10:38:07
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const int INF = 1e9;
const ll inf = 1LL<<60;

template<typename T>
bool chmin(T& x, const T& y){
  if(x <= y) return false;
  x = y;
  return true;
}
template<typename T>
bool chmax(T& x, const T& y){
  if(x >= y) return false;
  x = y;
  return true;
}

void solve() {
  ll n, V, c; cin >> n >> V >> c;
  vector<vector<ll>> dp(n+1, vector<ll>(V+1));
  vector<ll> v(n), w(n);
  for (int i=0; i<n; i++) cin >> v[i] >> w[i];
  for (int i=0; i<n; i++) {
    for (int j=0; j<=V; j++) {
      chmax(dp[i+1][j], dp[i][j]);
      if (j - v[i] >= 0) chmax(dp[i+1][j], dp[i][j-v[i]] + w[i] + c);
    }
    for (int j=0; j<=V; j++) {
      if (j - v[i] >= 0) chmax(dp[i+1][j], dp[i+1][j-v[i]] + w[i]);
    }
  }
  cout << *max_element(dp[n].begin(), dp[n].end()) << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  // int t; cin >> t;
  /*while (t--)*/ solve();
}
0