結果

問題 No.1947 質より種類数
ユーザー くまくま
提出日時 2022-06-07 19:01:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 7,695 ms
コンパイル使用メモリ 259,188 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 03:52:33
合計ジャッジ時間 6,872 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 21 ms
4,348 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 29 ms
4,348 KB
testcase_17 AC 37 ms
4,348 KB
testcase_18 AC 63 ms
4,348 KB
testcase_19 AC 55 ms
4,348 KB
testcase_20 AC 42 ms
4,348 KB
testcase_21 AC 50 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 24 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 64 ms
4,348 KB
testcase_30 AC 89 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 48 ms
4,348 KB
testcase_35 AC 52 ms
4,348 KB
testcase_36 AC 90 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
const int INF = 1e9;
const ll LINF = 1e18;
const double eps = 1e-10;
#define fi first
#define se second
#define eb emplace_back
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define srep(i, s, n) for (ll i = s; i < (ll)(n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fore(i,x) for(auto &i:x)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define sz(x) (ll)x.size()
#define dame { puts("-1"); return;}
#define yes { puts("Yes"); return;}
#define no { puts("No"); return;}
#define ret(x) { cout<<(x)<<'\n'; return;}
bool is_pop(ll hash, ll d){return (hash>>d)&1;}
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T,vc<T>,greater<T>>;
template<class... T>void in(T&... a) { (cin >> ... >> a); }
void out() { cout << '\n'; }
template<class T, class... Ts>void out(const T& a, const Ts&... b) { cout << a;(cout << ... << (cout << ' ', b));cout << '\n'; }
template< typename T >istream &operator>>(istream &is, vector< T > &v){for(T &in : v) is >> in;return is;}
template< typename T >ostream &operator<<(ostream &os, const vector< T > &v){for(int i = 0; i < (int) v.size(); i++) {os << v[i] << (i + 1 != (int) v.size() ? " " : "");}return os;}
template<class... T>constexpr auto min(T... a) { return min(initializer_list<common_type_t<T...>>{a...}); }
template<class... T>constexpr auto max(T... a) { return max(initializer_list<common_type_t<T...>>{a...}); }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void MAIN(); int main() { cin.tie(0); ios::sync_with_stdio(false); MAIN(); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void MAIN()
{
  ll n,V,c;
  in(n,V,c);
  vl dp(V+1,-1);
  dp[0] = 0;
  rep(i,n) {
    ll v,w;
    in(v,w);
    vl p = dp;
    rep(j,V+1) {
      if(j + v <= V && p[j] != -1) {
        chmax(dp[j+v],p[j]+w+c);
      }
    }
    rep(j,V+1) {
      if(j + v <= V && dp[j] != -1) {
        chmax(dp[j+v],dp[j]+w);
      }
    }
  }
  ll ans = 0;
  rep(i,V+1) chmax(ans,dp[i]);
  out(ans);
}
0