Skip to content

Commit 3129609

Browse files
authored
buttonbashing kattis
1 parent 7e2b50f commit 3129609

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Kattis/Button Bashing/Main4.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.*;
2+
3+
/**
4+
* Created by AMK on 8/6/2019.
5+
* Life is nice :)
6+
* Enjoy coding :D
7+
*/
8+
public class Main4 {
9+
public static void main(String[] args) {
10+
Scanner scanner = new Scanner(System.in);
11+
int q = scanner.nextInt();
12+
for (int i = 0; i < q; i++) {
13+
int n = scanner.nextInt();
14+
int t = scanner.nextInt();
15+
ArrayList<Integer> arrayList = new ArrayList<>();
16+
for (int j = 0; j < n; j++) {
17+
arrayList.add(scanner.nextInt());
18+
}
19+
int dist[] = new int[3605];
20+
Arrays.fill(dist, 3601);
21+
Queue<Integer> queue = new LinkedList<>();
22+
queue.add(0);
23+
dist[0] = 0;
24+
while (!queue.isEmpty()){
25+
int curr = queue.poll();
26+
for (int j = 0; j < arrayList.size(); j++) {
27+
int node = curr + arrayList.get(j);
28+
node = Math.max(0, node);
29+
node = Math.min(node, 3600);
30+
if (dist[node] > dist[curr] + 1){
31+
dist[node] = dist[curr] + 1;
32+
queue.add(node);
33+
}
34+
}
35+
}
36+
int min = 0;
37+
int time = 3601;
38+
for (int j = t; j < dist.length; j++) {
39+
if (dist[j] < time){
40+
min = j - t;
41+
time = dist[j];
42+
break;
43+
}
44+
}
45+
System.out.println(time + " " +min);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)