結果

問題 No.1430 Coup de Coupon
ユーザー 👑 ygussanyygussany
提出日時 2021-03-14 14:49:08
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 32,896 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 22:29:08
合計ジャッジ時間 1,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
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 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[5001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

long long chmin(long long* a, long long b)
{
	if (*a > b) *a = b;
}

int main()
{
	int i, N, C, c[2] = {}, P[5001], T, X, x[2][5001];
	scanf("%d %d", &N, &C);
	for (i = 0; i < N; i++) scanf("%d", &(P[i]));
	for (i = 1; i <= C; i++) {
		scanf("%d %d", &T, &X);
		T--;
		x[T][c[T]++] = X;
	}
	merge_sort(P, N);
	merge_sort(x[0], c[0]);
	merge_sort(x[1], c[1]);
	
	int j, k, cur, prev;
	long long dp[2][5001] = {};
	for (i = 0; i < N - C; i++) dp[0][0] += P[i];
	for (k = i, cur = 1, prev = 0; i < N; i++, cur ^= 1, prev ^= 1) {
		for (j = 0; j <= c[0]; j++) dp[cur][j] = (i - j - k <= c[1])? dp[prev][j] + P[i] / 100 * (100 - x[1][i-j-k]): 0; 
		for (j = 0; j < c[0]; j++) chmin(&(dp[cur][j+1]), dp[prev][j] + ((P[i] < x[0][j])? 0: P[i] - x[0][j]));
	}
	
	long long ans = 1LL << 60;
	for (j = 0; j <= c[0]; j++) chmin(&ans, dp[prev][j]);
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0