-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (42 loc) · 1.36 KB
/
Main.java
File metadata and controls
53 lines (42 loc) · 1.36 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int[] volume;
static int maxv = -1;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
volume = new int[N+1];
st = new StringTokenizer(br.readLine());
int c = 1;
while (st.hasMoreTokens()) {
volume[c] = Integer.parseInt(st.nextToken());
c++;
}
int[][] dp = new int[N + 1][M + 1];
dp[0][S]=1;
for (int i = 1; i < N+1; i++) {
for(int j=0; j<M+1;j++){
if(dp[i-1][j]==1){
if(j+volume[i]<=M){
dp[i][j+volume[i]]=1;
}
if(j-volume[i]>=0){
dp[i][j-volume[i]]=1;
}
}
}
}
for(int i=0; i<M+1;i++){
if(dp[N][i]==1){
maxv = Math.max(maxv, i);
}
}
System.out.println(maxv);
}
}