Submission #882147

#TimeUsernameProblemLanguageResultExecution timeMemory
882147rainboyFun Palace (CCO18_fun)C11
25 / 25
27 ms584 KiB
#include <stdio.h>
#include <string.h>

#define C	20000

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

int main() {
	static int dp[C + 1], dq[C + 1];
	int n, a, b, c, c_, x, ans;

	scanf("%d%d", &n, &b);
	memset(dp, -1, (C + 1) * sizeof *dp);
	for (c = 0; c < b; c++) 
		dp[c] = c;
	while (--n) {
		scanf("%d%d", &a, &b);
		memset(dq, -1, (C + 1) * sizeof *dq);
		x = -1;
		for (c = 0; c < a; c++)
			if (dp[c] != -1) {
				x = max(x, dp[c]);
				dq[c + b] = max(dq[c + b], dp[c] + b);
			}
		if (x != -1)
			for (c = 0; c < b; c++)
				dq[c] = max(dq[c], x + c);
		for (c = a; c <= C; c++) {
			c_ = c >= a + b ? c : c - a;
			dq[c_] = max(dq[c_], dp[c]);
		}
		memcpy(dp, dq, (C + 1) * sizeof *dq);
	}
	ans = 0;
	for (c = 0; c <= C; c++) 
		ans = max(ans, dp[c]);
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

Main.c: In function 'main':
Main.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d", &n, &b);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d", &a, &b);
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...