結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 👑 jupirojupiro
提出日時 2020-03-11 19:26:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 2,023 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 121,728 KB
実行使用メモリ 395,212 KB
最終ジャッジ日時 2024-04-27 19:23:09
合計ジャッジ時間 11,066 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 10 ms
26,180 KB
testcase_10 AC 5 ms
16,560 KB
testcase_11 AC 6 ms
24,192 KB
testcase_12 AC 50 ms
84,864 KB
testcase_13 AC 260 ms
306,688 KB
testcase_14 AC 26 ms
56,332 KB
testcase_15 AC 28 ms
79,568 KB
testcase_16 AC 59 ms
119,428 KB
testcase_17 AC 93 ms
165,220 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 5 ms
11,928 KB
testcase_22 AC 3 ms
10,336 KB
testcase_23 AC 3 ms
12,400 KB
testcase_24 AC 303 ms
395,156 KB
testcase_25 AC 314 ms
395,104 KB
testcase_26 AC 327 ms
395,128 KB
testcase_27 AC 308 ms
395,056 KB
testcase_28 AC 310 ms
395,108 KB
testcase_29 AC 307 ms
394,972 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 3 ms
11,872 KB
testcase_33 AC 4 ms
11,932 KB
testcase_34 AC 6 ms
13,072 KB
testcase_35 AC 294 ms
395,168 KB
testcase_36 AC 306 ms
395,184 KB
testcase_37 AC 306 ms
395,164 KB
testcase_38 AC 326 ms
395,104 KB
testcase_39 AC 316 ms
395,200 KB
testcase_40 AC 306 ms
395,144 KB
testcase_41 AC 305 ms
395,148 KB
testcase_42 AC 315 ms
395,048 KB
testcase_43 AC 312 ms
395,052 KB
testcase_44 AC 311 ms
395,212 KB
testcase_45 AC 314 ms
395,100 KB
testcase_46 AC 307 ms
395,020 KB
testcase_47 AC 310 ms
395,036 KB
testcase_48 AC 313 ms
394,980 KB
testcase_49 AC 310 ms
395,032 KB
testcase_50 AC 309 ms
395,120 KB
testcase_51 AC 316 ms
394,988 KB
testcase_52 AC 249 ms
349,324 KB
testcase_53 AC 312 ms
395,140 KB
testcase_54 AC 285 ms
395,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Pizza {
	ll p, d;
	Pizza(ll _p, ll _d) :p(_p), d(_d) {}
	bool operator<(const Pizza& pizza) {
		if (p == pizza.p) return d > pizza.d;
		return p > pizza.p;
	}
};

ll dp[5010][5010][2];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n, K; scanf("%lld %lld", &n, &K);
	for (int i = 0; i <= n; i++) for (int j = 0; j <= K; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = -1;
	vector<Pizza> v; v.reserve(n);
	for (int i = 0; i < n; i++) {
		ll p, d; scanf("%lld %lld", &p, &d);
		v.emplace_back(p, d);
	}
	sort(v.begin(), v.end());
	dp[0][0][0] = 0;
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j <= K; j++) {
			if (dp[i][j][0] != -1 && j + v[i].p <= K) chmax(dp[i + 1][j + v[i].p][1], dp[i][j][0] + v[i].d);
			chmax(dp[i + 1][j][0], dp[i][j][0]);
			chmax(dp[i + 1][j][1], dp[i][j][1]);
			if (dp[i][j][1] != -1) chmax(dp[i + 1][j][0], dp[i][j][1] + v[i].d);
		}
	}
	ll res = 0;
	for (ll i = 0; i <= K; i++) chmax(res, max(dp[n][i][0], dp[n][i][1]));
	cout << res << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0