답안 #532277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532277 2022-03-02T16:32:42 Z rainboy 만두 (JOI14_ho_t2) C
100 / 100
19 ms 464 KB
#include <stdio.h>
#include <string.h>

#define N	10000
#define INF	0x3f3f3f3f

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

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

void sort(int *aa, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[j] == a)
				j++;
			else if (aa[j] > a) {
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
			}
		sort(aa, l, i);
		l = k;
	}
}

int main() {
	static int aa[N], dp[N + 1];
	int n, m, i, j, ans;

	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++)
		scanf("%d", &aa[i]);
	sort(aa, 1, n + 1);
	for (i = 1; i <= n; i++)
		aa[i] += aa[i - 1];
	memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0;
	while (m--) {
		int c, p;

		scanf("%d%d", &c, &p);
		for (i = n; i >= 0; i--) {
			j = min(i + c, n);
			dp[j] = min(dp[j], dp[i] + p);
		}
	}
	ans = 0;
	for (i = 0; i <= n; i++)
		if (dp[i] != INF)
			ans = max(ans, aa[i] - dp[i]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

2014_ho_t2.c: In function 'main':
2014_ho_t2.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
2014_ho_t2.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
2014_ho_t2.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d%d", &c, &p);
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 3 ms 296 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 276 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 328 KB Output is correct
2 Correct 8 ms 356 KB Output is correct
3 Correct 9 ms 400 KB Output is correct
4 Correct 11 ms 388 KB Output is correct
5 Correct 10 ms 384 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 9 ms 336 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 9 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 3 ms 296 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 276 KB Output is correct
8 Correct 0 ms 288 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 9 ms 328 KB Output is correct
12 Correct 8 ms 356 KB Output is correct
13 Correct 9 ms 400 KB Output is correct
14 Correct 11 ms 388 KB Output is correct
15 Correct 10 ms 384 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 8 ms 336 KB Output is correct
18 Correct 9 ms 336 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 9 ms 300 KB Output is correct
21 Correct 19 ms 336 KB Output is correct
22 Correct 14 ms 336 KB Output is correct
23 Correct 14 ms 300 KB Output is correct
24 Correct 16 ms 336 KB Output is correct
25 Correct 16 ms 336 KB Output is correct
26 Correct 19 ms 432 KB Output is correct
27 Correct 4 ms 208 KB Output is correct
28 Correct 12 ms 464 KB Output is correct
29 Correct 13 ms 404 KB Output is correct
30 Correct 13 ms 336 KB Output is correct