結果
問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
ユーザー |
![]() |
提出日時 | 2020-01-01 19:12:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,555 bytes |
コンパイル時間 | 1,781 ms |
コンパイル使用メモリ | 128,984 KB |
最終ジャッジ日時 | 2025-01-08 15:17:45 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 21 WA * 31 |
ソースコード
#include <cmath> #include <vector> #include <list> #include <map> #include <set> #include <functional> #include <queue> #include <iostream> #include <string.h> #include <iomanip> #include <algorithm> #include <functional> #include <cstdint> #include <climits> #include <unordered_set> #include <unordered_map> #include <sstream> #include <stack> using namespace std; typedef long long int ll; typedef pair<char,char> pcc; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> t3; #define rep(i,a) for(ll i = 0;i < a;i++) template <class T> void cmax(T& a, const T b){a=max(a,b);} const ll mod = 1e9+7; int main(void) { ll n,k; cin >> n >> k; vector<P> vs(n); rep(i,n){ cin >> vs[i].first >> vs[i].second; } sort(vs.begin(),vs.end(),[&](P a, P b){ if(a.first == b.first){ return a.second > b.second; } return a.first > b.first; }); vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(k+10, vector<ll>(2,0))); rep(i,n){ auto p = vs[i].first; auto d = vs[i].second; for(int j = 0;j <= k;j++){ cmax(dp[1][j][0],dp[0][j][0]); cmax(dp[1][j][1],dp[0][j][1]); if(dp[0][j][1] != 0){ cmax(dp[1][j][0],dp[0][j][1] + d); } } for(int j = 0;j+p <= k;j++){ cmax(dp[1][j+p][1], dp[0][j][0] + d); } swap(dp[0], dp[1]); } ll m = 0; rep(j,k+1){ cmax(m, dp[1][j][0]); cmax(m, dp[1][j][1]); } cout << m << endl; return 0; }