Submission #10298400


Source Code Expand

/* Coached by Dukkha */
#include <stdio.h>

#define N 100

int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int ww[N], vv[N], dp[N + 1][N + 1][N * 3 + 1];
	int n, w_, w0, i, k, a, b, ans;

	scanf("%d%d", &n, &w_);
	for (i = 0; i < n; i++)
		scanf("%d%d", &ww[i], &vv[i]);
	w0 = ww[0];
	for (i = 0; i < n; i++)
		ww[i] -= w0;
	for (i = 0; i < n; i++) {
		int w = ww[i], v = vv[i];

		for (k = 0; k <= i; k++)
			for (a = 0; a <= n * 3; a++) {
				dp[i + 1][k][a] = max(dp[i + 1][k][a], dp[i][k][a]);
				if ((b = a + w) <= n * 3)
					dp[i + 1][k + 1][b] = max(dp[i + 1][k + 1][b], dp[i][k][a] + v);
			}
	}
	ans = 0;
	for (k = 1; k <= n; k++)
		if (w_ >= (long long) w0 * k)
			for (a = 0; a <= w_ - w0 * k && a <= n * 3; a++)
				ans = max(ans, dp[n][k][a]);
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Simple Knapsack
User kaiboy
Language C (GCC 5.4.1)
Score 400
Code Size 851 Byte
Status AC
Exec Time 6 ms
Memory 10368 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:12:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &w_);
  ^
./Main.c:14:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &ww[i], &vv[i]);
   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 16
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 6 ms 10368 KB
antigreedy1 AC 6 ms 10368 KB
antigreedy2 AC 6 ms 10368 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 0 ms 128 KB
example3 AC 1 ms 128 KB
quarter0 AC 6 ms 10368 KB
quarter1 AC 6 ms 10368 KB
quarter2 AC 6 ms 10368 KB
rand0 AC 1 ms 256 KB
rand1 AC 2 ms 4480 KB
rand2 AC 1 ms 2432 KB
smallw0 AC 6 ms 10368 KB
smallw1 AC 6 ms 10368 KB
smallw2 AC 6 ms 10368 KB