結果

問題 No.617 Nafmo、買い出しに行く
ユーザー cww
提出日時 2018-04-08 04:32:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 198,628 KB
最終ジャッジ日時 2025-01-05 10:00:08
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A( N );
    for( auto &x : A )
    {
        cin >> x;
    }
    vector<vector<int>> dp( N + 1, vector<int>( K + 1 ) );
    for( int i = 1; i <= N; ++i )
    {
        for( int j = 0; j <= K; ++j )
        {
            if( A[ i - 1 ] <= j )
            {
                dp[ i ][ j ] = max( dp[ i - 1 ][ j ], dp[ i - 1 ][ j - A[ i - 1 ] ]  + A[ i - 1 ] );
            }
            else
            {
                dp[ i ][ j ] = dp[ i - 1 ][ j ];
            }
        }
    }
    cout << dp[ N ][ K ] << endl;
    return 0;
}
0