-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1082.java
More file actions
39 lines (33 loc) · 1.16 KB
/
BOJ1082.java
File metadata and controls
39 lines (33 loc) · 1.16 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
package ¹éÁØ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class BOJ1082 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
BigInteger ten = BigInteger.TEN;
int[] p = new int[N];
for(int i = 0; i < N; i++) {
p[i] = Integer.parseInt(st.nextToken());
}
int M = Integer.parseInt(br.readLine());
BigInteger[] dp = new BigInteger[M+1];
for(int i = 0; i <= M; i++) {
dp[i] = BigInteger.valueOf(-1);
}
for(int i = N-1; i >= 0; i--) {
int x = p[i];
for(int j = x; j <= M; j++) {
BigInteger a = dp[j-x].multiply(ten);
BigInteger b = BigInteger.valueOf(i);
BigInteger c = a.add(b);
dp[j] = dp[j].max(c.max(b));
}
}
System.out.print(dp[M]);
}
}