Submission #479396

# Submission time Handle Problem Language Result Execution time Memory
479396 2021-10-11T15:15:44 Z rainboy Sličice (COCI19_slicice) C
90 / 90
164 ms 324 KB
#include <stdio.h>
#include <string.h>

#define N	500
#define M	500
#define K	500

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

int main() {
	static int aa[N], bb[M + 1], dp[K + 1];
	int n, m, k, i, j, s, c;

	scanf("%d%d%d", &n, &m, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (j = 0; j <= m; j++)
		scanf("%d", &bb[j]);
	memset(dp, -1, (k + 1) * sizeof *dp), dp[0] = 0;
	for (i = 0; i < n; i++)
		for (s = k; s >= 0; s--)
			for (c = 0; aa[i] + c <= m && c <= s; c++)
				if (dp[s - c] != -1)
					dp[s] = max(dp[s], dp[s - c] + bb[aa[i] + c]);
	printf("%d\n", dp[k]);
	return 0;
}

Compilation message

slicice.c: In function 'main':
slicice.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d%d%d", &n, &m, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
slicice.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
slicice.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d", &bb[j]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 161 ms 264 KB Output is correct
4 Correct 161 ms 324 KB Output is correct
5 Correct 156 ms 204 KB Output is correct
6 Correct 154 ms 264 KB Output is correct
7 Correct 151 ms 264 KB Output is correct
8 Correct 164 ms 324 KB Output is correct
9 Correct 150 ms 268 KB Output is correct
10 Correct 162 ms 268 KB Output is correct