1
+ # w = int(input())
2
+ # n, k = map(int, input().split())
3
+ # a = []
4
+ # b = []
5
+ # for i in range(n):
6
+ # a_, b_ = map(int,input().split())
7
+ # a.append(a_)
8
+ # b.append(b_)
9
+
10
+ # dp = [[0]*(w+1) for _ in range(n+1)]
11
+
12
+ # rest = w
13
+
14
+ # for i in range(n):
15
+ # for j in range(w+1):
16
+ # if a[i] > j:
17
+ # dp[i+1][j] = dp[i][j]
18
+ # else:
19
+ # dp[i+1][j] = max(dp[i][j], dp[i][j-a[i]]+b[i])
20
+ # print(dp[n][w])
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ #3次元dp MLE
29
+
30
+ # w = int(input())
31
+ # n, k = map(int, input().split())
32
+ # a = []
33
+ # b = []
34
+ # for i in range(n):
35
+ # a_, b_ = map(int, input().split())
36
+ # a.append(a_)
37
+ # b.append(b_)
38
+
39
+ # dp = [[[0] * (w + 1) for i in range(k + 1)] for j in range(n + 1)]
40
+
41
+ # # dp[i][j][l] := i 番目まで見て、j 枚使用し、幅が合計 l のときの最大値
42
+ # for i in range(n):
43
+ # for j in range(k + 1):
44
+ # for l in range(w + 1):
45
+ # if j == k: # この枚数以上貼れない
46
+ # dp[i + 1][j][l] = dp[i][j][l]
47
+ # else:
48
+ # if l < a[i]: # 幅が足りない
49
+ # dp[i + 1][j][l] = dp[i][j][l]
50
+ # else:
51
+ # dp[i + 1][j][l] = max(dp[i][j][l], dp[i][j - 1][l - a[i]] + b[i])
52
+
53
+ # # 必ず k 枚使う必要はない
54
+ # ans = 0
55
+ # for i in range(k + 1):
56
+ # ans = max(ans, dp[n][i][w])
57
+
58
+ # print(ans)
59
+
60
+ w = int (input ())
61
+ n , k = map (int , input ().split ())
62
+
63
+ dp = [[0 ] * (w + 1 ) for i in range (k + 1 )]
64
+ ans = 0
65
+ for i in range (n ):
66
+ a , b = map (int , input ().split ())
67
+ for j in range (k , 0 , - 1 ):
68
+ for l in range (w , 0 , - 1 ):
69
+ if 0 <= l - a :
70
+ dp [j ][l ] = max (dp [j ][l ], dp [j - 1 ][l - a ] + b )
71
+ ans = max (dp [j ][l ], ans )
72
+
73
+ print (ans )
74
+
75
+ # w = int(input())
76
+ # n, k = map(int, input().split())
77
+ # dp = [[0]*(w+1) for i in range(k+1)]
78
+ # ans = 0
79
+ # for _ in range(n):
80
+ # a,b = map(int, input().split())
81
+ # for j in range(k, 0, -1):
82
+ # for p in range(w, 0, -1):
83
+ # if p-a >= 0:
84
+ # dp[j][p] =max(dp[j][p], dp[j-1][p-a] + b)
85
+ # ans = max(ans, dp[j][p])
86
+
87
+ # print(ans)
0 commit comments