結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー minatominato
提出日時 2020-08-27 08:22:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,262 bytes
コンパイル時間 3,520 ms
コンパイル使用メモリ 249,320 KB
実行使用メモリ 202,652 KB
最終ジャッジ日時 2024-04-27 03:27:01
合計ジャッジ時間 8,413 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 7 ms
16,452 KB
testcase_10 AC 4 ms
9,880 KB
testcase_11 AC 6 ms
17,992 KB
testcase_12 AC 31 ms
47,836 KB
testcase_13 AC 131 ms
177,452 KB
testcase_14 AC 20 ms
30,416 KB
testcase_15 AC 19 ms
41,580 KB
testcase_16 AC 30 ms
79,648 KB
testcase_17 AC 55 ms
147,992 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 4 ms
8,028 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 4 ms
7,864 KB
testcase_24 AC 136 ms
200,824 KB
testcase_25 AC 145 ms
200,872 KB
testcase_26 AC 133 ms
200,864 KB
testcase_27 AC 134 ms
202,652 KB
testcase_28 AC 112 ms
201,320 KB
testcase_29 AC 109 ms
202,056 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 3 ms
7,792 KB
testcase_33 AC 4 ms
7,840 KB
testcase_34 AC 5 ms
8,336 KB
testcase_35 AC 127 ms
201,052 KB
testcase_36 AC 131 ms
200,916 KB
testcase_37 AC 126 ms
201,120 KB
testcase_38 AC 140 ms
201,064 KB
testcase_39 AC 142 ms
201,320 KB
testcase_40 AC 121 ms
201,036 KB
testcase_41 AC 127 ms
201,108 KB
testcase_42 AC 132 ms
201,500 KB
testcase_43 AC 132 ms
201,904 KB
testcase_44 AC 133 ms
201,400 KB
testcase_45 AC 133 ms
200,900 KB
testcase_46 AC 104 ms
201,716 KB
testcase_47 AC 108 ms
200,964 KB
testcase_48 AC 110 ms
201,436 KB
testcase_49 AC 112 ms
200,748 KB
testcase_50 AC 109 ms
202,448 KB
testcase_51 AC 109 ms
202,208 KB
testcase_52 AC 92 ms
201,708 KB
testcase_53 AC 101 ms
201,016 KB
testcase_54 AC 85 ms
201,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() {cout << "\n";}
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int dp[5050][5050][2];
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<int> P(N),D(N);
    rep(i,N) cin >> P[i] >> D[i];

    vector<int> idx(N);
    iota(all(idx),0);
    sort(all(idx),[&](int i, int j){return P[i]>P[j];});

    rep(i,N+1) rep(j,K+1) rep(k,2) dp[i][j][k] = -1e9;
    dp[0][0][0] = 0;
    rep(i,N) {
        int u = idx[i];
        rep(j,K+1) {
            rep(k,2) {
                if (dp[i][j][k]==-1e9) continue;
                chmax(dp[i+1][j][k],dp[i][j][k]);
                if (!k and j+P[u]<=K) chmax(dp[i+1][j+P[u]][k^1],dp[i][j][k]+D[u]);
                if (k) chmax(dp[i+1][j][k^1],dp[i][j][k]+D[u]);
            }
        }
    }

    int ans = 0;
    rep(j,K+1) rep(k,2) chmax(ans,dp[N][j][k]);

    cout << ans << ln; 
}
0