結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー rabimearabimea
提出日時 2023-02-15 04:15:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 202,764 KB
実行使用メモリ 199,380 KB
最終ジャッジ日時 2023-09-24 14:28:41
合計ジャッジ時間 12,406 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
10,460 KB
testcase_10 AC 7 ms
7,152 KB
testcase_11 AC 8 ms
8,780 KB
testcase_12 AC 62 ms
47,032 KB
testcase_13 AC 235 ms
176,600 KB
testcase_14 AC 38 ms
29,616 KB
testcase_15 AC 43 ms
34,776 KB
testcase_16 AC 66 ms
54,356 KB
testcase_17 AC 102 ms
83,464 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 7 ms
6,584 KB
testcase_22 AC 4 ms
4,960 KB
testcase_23 AC 5 ms
5,620 KB
testcase_24 AC 278 ms
199,164 KB
testcase_25 AC 279 ms
199,164 KB
testcase_26 AC 279 ms
199,156 KB
testcase_27 AC 281 ms
199,160 KB
testcase_28 AC 269 ms
199,192 KB
testcase_29 AC 267 ms
199,112 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 4 ms
5,192 KB
testcase_33 AC 5 ms
5,908 KB
testcase_34 AC 7 ms
7,288 KB
testcase_35 AC 272 ms
199,160 KB
testcase_36 AC 275 ms
199,144 KB
testcase_37 AC 274 ms
199,320 KB
testcase_38 AC 279 ms
199,108 KB
testcase_39 AC 279 ms
199,104 KB
testcase_40 AC 276 ms
199,140 KB
testcase_41 AC 278 ms
199,156 KB
testcase_42 AC 285 ms
199,144 KB
testcase_43 AC 279 ms
199,148 KB
testcase_44 AC 280 ms
199,208 KB
testcase_45 AC 281 ms
199,248 KB
testcase_46 AC 265 ms
199,104 KB
testcase_47 AC 265 ms
199,248 KB
testcase_48 AC 263 ms
199,104 KB
testcase_49 AC 263 ms
199,152 KB
testcase_50 AC 263 ms
199,144 KB
testcase_51 AC 263 ms
199,152 KB
testcase_52 AC 258 ms
199,100 KB
testcase_53 AC 272 ms
199,380 KB
testcase_54 AC 167 ms
121,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 5e3 + 11;

int f[N][N], g[N][N];

pii pizza[N]; // {p, d}
void upd(int &a, int b) {
	if(a < b) a = b;
}

int main() {
	ios::sync_with_stdio(0);
	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i ++)
		cin >> pizza[i].fi >> pizza[i].se;
	
	sort(pizza + 1, pizza + n + 1);
	
	for(int i = 0; i < n; i ++) {
		auto [p, d] = pizza[i + 1];
		for(int j = 0; j <= k; j ++) {
			upd(f[i + 1][j], f[i][j]);
			upd(g[i + 1][j], g[i][j]);
			
			upd(g[i + 1][j], f[i][j] + d);
			if(j + p <= k)
				upd(f[i + 1][j + p], g[i][j] + d);
		}
	}
	
	int ans = 0;
	for(int j = 0; j <= k; j ++)
		upd(ans, f[n][j]);
	cout << ans << '\n';
}

0