結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー tarattata1tarattata1
提出日時 2019-12-14 00:38:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 81,524 KB
実行使用メモリ 198,588 KB
最終ジャッジ日時 2023-09-10 08:12:42
合計ジャッジ時間 7,258 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 7 ms
16,136 KB
testcase_10 AC 5 ms
10,048 KB
testcase_11 AC 6 ms
15,832 KB
testcase_12 AC 36 ms
47,968 KB
testcase_13 AC 136 ms
174,728 KB
testcase_14 AC 22 ms
29,484 KB
testcase_15 AC 23 ms
41,332 KB
testcase_16 AC 37 ms
77,876 KB
testcase_17 AC 63 ms
141,764 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 4 ms
6,428 KB
testcase_22 AC 3 ms
5,652 KB
testcase_23 AC 4 ms
5,956 KB
testcase_24 AC 193 ms
198,564 KB
testcase_25 AC 183 ms
198,492 KB
testcase_26 AC 160 ms
198,528 KB
testcase_27 AC 160 ms
198,532 KB
testcase_28 AC 149 ms
198,496 KB
testcase_29 AC 151 ms
198,556 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 3 ms
5,780 KB
testcase_33 AC 3 ms
6,100 KB
testcase_34 AC 5 ms
6,996 KB
testcase_35 AC 167 ms
198,560 KB
testcase_36 AC 164 ms
198,532 KB
testcase_37 AC 167 ms
198,496 KB
testcase_38 AC 169 ms
198,508 KB
testcase_39 AC 167 ms
198,552 KB
testcase_40 AC 160 ms
198,536 KB
testcase_41 AC 160 ms
198,588 KB
testcase_42 AC 160 ms
198,560 KB
testcase_43 AC 160 ms
198,544 KB
testcase_44 AC 160 ms
198,564 KB
testcase_45 AC 158 ms
198,552 KB
testcase_46 AC 150 ms
198,532 KB
testcase_47 AC 150 ms
198,492 KB
testcase_48 AC 150 ms
198,536 KB
testcase_49 AC 149 ms
198,496 KB
testcase_50 AC 152 ms
198,504 KB
testcase_51 AC 151 ms
198,528 KB
testcase_52 AC 128 ms
191,064 KB
testcase_53 AC 146 ms
198,512 KB
testcase_54 AC 140 ms
198,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

int dp[5005][5005][2];

int main(int argc, char* argv[])
{
    int n,K;
    scanf("%d%d", &n, &K);
    vector<pair<int,int> > z(n);
    int i,j,k;
    for(i=0; i<n; i++) {
        int p,d;
        scanf("%d%d", &p, &d);
        z[i]=make_pair(p,d);
    }
    sort(z.rbegin(),z.rend());

    for(i=0; i<n; i++) {
        for(j=0; j<=K; j++) {
            for(k=0; k<2; k++) {
                dp[i][j][k]=-INF;
            }
        }
    }

    dp[0][K][0]=0;
    for(i=0; i<n; i++) {
        for(j=0; j<=K; j++) {
            for(k=0; k<2; k++) {
                dp[i+1][j][k]=dp[i][j][k];
            }
        }
        for(j=0; j<=K; j++) {
            for(k=0; k<2; k++) {
                if(dp[i][j][k]>=0) {
                    int j2=(k==0? j-z[i].first: j);
                    if(j2>=0 && j2<=K) {
                        dp[i+1][j2][1-k]=MAX(dp[i+1][j2][1-k],dp[i][j][k]+z[i].second);
                    }
                }
            }
        }
    }

    int ans=0;
    for(j=0; j<=K; j++) {
        for(k=0; k<2; k++) {
            ans=MAX(ans,dp[n][j][k]);
        }
    }
    printf("%d\n", ans);

    return 0;
}
0