結果
問題 |
No.1947 質より種類数
|
ユーザー |
|
提出日時 | 2022-06-07 19:01:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 2,506 bytes |
コンパイル時間 | 4,140 ms |
コンパイル使用メモリ | 251,404 KB |
最終ジャッジ日時 | 2025-01-29 18:55:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 37 |
ソースコード
#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); }