-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathP1616.c
More file actions
27 lines (25 loc) · 693 Bytes
/
P1616.c
File metadata and controls
27 lines (25 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
int main() {
int t, m;
scanf("%d %d", &t, &m);
int * dp = (int *)malloc((t + 1) * sizeof(int));
memset(dp, 0, (t + 1) * sizeof(int));
short * time = (short *)malloc(m * sizeof(short));
short * value = (short *)malloc(m * sizeof(short));
for (int i = 0; i < m; i++) {
scanf("%hd %hd", time + i, value + i);
}
for (int i = 0; i < m; i++)
for (int j = time[i]; j <= t; j++)
dp[j] = max(dp[j], dp[j - time[i]] + value[i]);
printf("%d", dp[t]);
free(dp);
free(time);
free(value);
return 0;
}