USACO Score Inflation

Code

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
28
29
30
31
32
33
34
35
/*
ID: wcr19961
PROG: inflate
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;

const int maxn = 10010;
int dp[maxn];


int main() {
freopen("inflate.in", "r", stdin);
freopen("inflate.out", "w", stdout);
int m, n;
scanf("%d%d", &m, &n);
for (int i = 0; i < n; ++i) {
int w, c;
scanf("%d%d", &w, &c);
for (int j = c; j <= m; ++j) {
dp[j] = max(dp[j], dp[j - c] + w);
}
}
int ans = 0;
for (int i = 0; i <= m; ++i) {
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
return 0;
}