-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoredVivek.java
33 lines (28 loc) · 974 Bytes
/
BoredVivek.java
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
import java.util.Scanner;
public class BoredVivek {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int W = sc.nextInt();
int N = sc.nextInt();
int L = sc.nextInt();
int[] width = new int[N];
int[] beauty = new int[N];
for (int i = 0; i < N; i++) {
width[i] = sc.nextInt();
beauty[i] = sc.nextInt();
}
int[][][] dp = new int[N+1][W+1][L+1];
for (int i = 0; i < N; i++) {
for (int j = 1; j <= W; j++) {
for (int k = 1; k <= L; k++) {
if (width[i] <= j) {
dp[i+1][j][k] = Math.max(dp[i][j - width[i]][k-1] + beauty[i], dp[i][j][k]);
} else {
dp[i+1][j][k] = dp[i][j][k];
}
}
}
}
System.out.println(dp[N][W][L]);
}
}