結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー WarToksWarToks
提出日時 2020-01-03 09:51:39
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,410 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 105,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 13:40:49
合計ジャッジ時間 6,253 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 39 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 53 ms
4,376 KB
testcase_25 AC 54 ms
4,376 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 57 ms
4,380 KB
testcase_28 AC 55 ms
4,376 KB
testcase_29 AC 54 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 46 ms
4,380 KB
testcase_36 AC 46 ms
4,380 KB
testcase_37 AC 45 ms
4,384 KB
testcase_38 AC 45 ms
4,380 KB
testcase_39 AC 48 ms
4,376 KB
testcase_40 AC 48 ms
4,380 KB
testcase_41 AC 49 ms
4,384 KB
testcase_42 AC 52 ms
4,380 KB
testcase_43 AC 52 ms
4,380 KB
testcase_44 AC 52 ms
4,380 KB
testcase_45 AC 51 ms
4,376 KB
testcase_46 AC 59 ms
4,376 KB
testcase_47 AC 56 ms
4,376 KB
testcase_48 AC 55 ms
4,380 KB
testcase_49 AC 56 ms
4,380 KB
testcase_50 AC 56 ms
4,384 KB
testcase_51 AC 57 ms
4,380 KB
testcase_52 AC 46 ms
4,380 KB
testcase_53 AC 55 ms
4,376 KB
testcase_54 AC 47 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int inf = 1e9;
std::vector<std::pair<int, int>> A;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    A.resize(n); REP(i, n) scanf("%d%d", &A[i].first, &A[i].second);
    std::sort(A.begin(), A.end(), std::greater<std::pair<int, int>>());

    std::vector<int> P(k + 1, -inf), Q(k + 1, -inf), PP(k + 1, -inf), QQ(k + 1, -inf);
    P[0] = 0;
    for(auto& itr : A){
        int p = itr.first, c = itr.second;
        for(int e = 0; e <= k; ++e){
            chmax(PP[e], Q[e] + c); // 無料の交換
            chmax(PP[e], P[e]);
            chmax(QQ[e], Q[e]);
            if(e + p <= k) chmax(QQ[e + p], P[e] + c);
        }
        std::swap(P, PP);
        std::swap(Q, QQ);
    }
    int res = 0;
    for(int x = 0; x <= k; ++x){
        if(res < P[x]) res = P[x];
        if(res < Q[x]) res = Q[x];
    }
    printf("%d\n", res);

    

    
    
    return 0;
}
0