-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdleGameA.java
59 lines (54 loc) · 2.2 KB
/
IdleGameA.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.*;
import java.math.*;
import java.util.*;
public class IdleGameA {
private static int calculateMinimum(int maxLevel, int amountRequired, int[] values, int[] costs) {
return calculateMin(maxLevel, amountRequired,values,costs,0,0,0);
}
private static int calculateMin(int maxLevel, int amountRequired, int[] values, int[] costs, int currLevel, int currAmount, int totalTap) {
if (currAmount >= amountRequired) {
return totalTap;
}
else {
if(currLevel == maxLevel) {
return calculateMin(maxLevel, amountRequired,values,costs,currLevel,currAmount+values[currLevel],totalTap+1);
}
else {
if (currAmount-costs[currLevel+1]>=0) {
ArrayList<Integer> totalTaps = new ArrayList<Integer>();
for(int i=currLevel+1;i<=maxLevel; i++) {
if(currAmount-costs[i]>=0) {
int number1=calculateMin(maxLevel, amountRequired,values,costs,i,currAmount-costs[i],totalTap);
totalTaps.add(number1);
}
}
int number2=calculateMin(maxLevel, amountRequired,values,costs,currLevel,currAmount+values[currLevel],totalTap+1);
totalTaps.add(number2);
return Collections.min(totalTaps);
}
else {
return calculateMin(maxLevel, amountRequired,values,costs,currLevel,currAmount+values[currLevel],totalTap+1);
}
}
}
}
public static void main(String[] args) {
//System.setIn(new FileInputStream("test.txt"));
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
for (int tc = 0; tc < testCases; tc++) {
int maxLevel = sc.nextInt();
int amountRequired = sc.nextInt();
int[] values = new int[maxLevel + 1];
for (int i = 0; i <= maxLevel; i++) {
values[i] = sc.nextInt();
}
int[] costs = new int[maxLevel + 1];
for (int i = 0; i <= maxLevel; i++) {
costs[i] = sc.nextInt();
}
int solution = calculateMinimum(maxLevel, amountRequired, values, costs);
System.out.println(solution);
}
}
}