Submission #532276

# Submission time Handle Problem Language Result Execution time Memory
532276 2022-03-02T16:31:44 Z rainboy None (JOI14_ho_t2) C
0 / 100
1 ms 336 KB
#include <stdio.h>
#include <string.h>

#define N	500
#define M	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[M + 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:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
2014_ho_t2.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
2014_ho_t2.c:50:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%d%d", &c, &p);
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 292 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 336 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -