-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtmQueue.java
51 lines (44 loc) · 987 Bytes
/
AtmQueue.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
package earth;
import java.util.*;
public class AtmQueue {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=1;i<=t;i++) {
int n=sc.nextInt();
int x=sc.nextInt();
int arr[]=new int[n];
for(int k=0;k<n;k++) {
arr[k]=sc.nextInt();
}
int res[]=order(arr,x);
System.out.print("case #"+i+": ");
for(int j=0;j<res.length;j++) {
System.out.print(res[j]+" ");
}
System.out.print("\n");
}
}
static int[] order(int []a,int x) {
Deque<Integer> dq=new ArrayDeque<Integer>();
List<Integer> li=new ArrayList<Integer>();
for(int i=1;i<=a.length;i++) {
dq.offer(i);
}
while(!dq.isEmpty()) {
int index=dq.poll();
int amt=a[index-1];
if(amt<=x) {
li.add(index);
}else {
a[index-1]=amt-x;
dq.offer(index);
}
}
int arr[]=new int[li.size()];
for(int k=0;k<arr.length;k++) {
arr[k]=li.get(k);
}
return arr;
}
}