結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー bal4ubal4u
提出日時 2019-12-19 17:31:07
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 29,848 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-21 07:07:18
合計ジャッジ時間 4,357 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yuki 951 【本日限定】1枚頼むともう1枚無料!
// 2019.12.19 bal4u

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int getchar_unlocked(void);
#define gc() getchar_unlocked()

int in() {  // 整数の入力
	int n = 0; int c;
	do c = gc(); while (isspace(c));
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int p, d; } T;
T t[5005];
typedef struct { int d, a, b; } DP;
DP dp[100005];
int N, K;

int cmp(const void *u, const void *v) {
	int t = ((T *)v)->p - ((T *)u)->p;
	if (t) return t;
	return ((T *)v)->d - ((T *)u)->d;
}

int main()
{
	int i, j, k, ans;

	N = in(), K = in();
	for (i = 0; i < N; ++i) t[i].p = in(), t[i].d = in();
	qsort(t, N, sizeof(T), cmp);

	dp[0].d = 0;
	for (i = 2*K; i >= 1; --i) dp[i].d = -1;
	for (i = 0; i < N; ++i) {
		for (j = K; j >= 0; --j) if (dp[j].d >= 0) {
			k = j+t[i].p;
			if (dp[k].d < dp[j].d + t[i].d) {
				dp[k].d = dp[j].d + t[i].d;
				dp[k].a = dp[j].a + 1, dp[k].b = dp[j].b + 1;
			}
			if (2*dp[j].a > dp[j].b) dp[j].d += t[i].d, dp[j].b++;
		}
	}
	
	ans = 0;
	for (i = K; i >= 0; --i) {
		if (dp[i].d > ans) ans = dp[i].d;
	}
	printf("%d\n", ans);
	return 0;
}
0