結果
問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
ユーザー |
![]() |
提出日時 | 2019-12-19 18:17:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 734 bytes |
コンパイル時間 | 1,864 ms |
コンパイル使用メモリ | 175,404 KB |
実行使用メモリ | 118,784 KB |
最終ジャッジ日時 | 2024-07-07 01:36:13 |
合計ジャッジ時間 | 7,066 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 6 RE * 4 TLE * 1 -- * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; const long long INF = 1e18; void chmax(ll *a,ll b){ if (*a<b) *a=b; return; } int main(){ ll N,K; cin>>N>>K; vector<ll> p(N),d(N); rep(i,N) cin>>p[i]>>d[i]; vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(N+1,vector<ll>(K+1,0))); rep(i,N)rep(j,K+1){ chmax(&dp[0][i+1][j],dp[0][i][j]); if (j+d[i]<=K) chmax(&dp[1][i+1][j+p[i]],dp[0][i][j]+d[i]); if (dp[1][i][j]==0) continue; chmax(&dp[1][i+1][j],dp[1][i][j]); chmax(&dp[0][i+1][j],dp[1][i][j]+d[i]); } cout<<(dp[0][N][K]<dp[1][N][K] ? dp[1][N][K] : dp[0][N][K])<<endl; return 0; }