-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamps.txt
53 lines (51 loc) · 1.63 KB
/
stamps.txt
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
/*
ID: achyuta2
LANG: JAVA
TASK: stamps
*/
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class stamps {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("stamps.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("stamps.out")),true);
StringTokenizer st = new StringTokenizer(f.readLine());
int stampcount = Integer.parseInt(st.nextToken());
int valcount = Integer.parseInt(st.nextToken());
int[] stamps = new int[valcount];
int rows = (int)Math.ceil(valcount/15.0);
int counter =0;
for(int i=0; i<rows; i++){
st = new StringTokenizer(f.readLine());
while (st.hasMoreTokens()) {
stamps[counter] = Integer.parseInt(st.nextToken());
counter++;
}
}
int max = Integer.MIN_VALUE;
for(int i=0; i<valcount; i++){
if(max<stamps[i]){
max=stamps[i];
}
}
int[] dp = new int[max*stampcount+1];
System.out.println(Arrays.toString(stamps));
int currmax = 0;
for(int i=1; i<dp.length; i++){
dp[i]=stampcount+1;
for(int j:stamps){
if(i-j>-1){
dp[i]= Math.min(dp[i], dp[i - j] + 1);
}
}
if(dp[i]<=stampcount){
currmax++;
}else{
break;
}
}
out.println(currmax);
out.close();
}
}