-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj2346.java
More file actions
64 lines (49 loc) · 1.55 KB
/
boj2346.java
File metadata and controls
64 lines (49 loc) · 1.55 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;
public class boj2346 {
static int N;
static Deque<Balloon> deque;
static StringBuilder sb = new StringBuilder();
static class Balloon {
int idx, num;
public Balloon(int idx, int num) {
this.idx = idx;
this.num = num;
}
}
public static void main(String[] args) throws IOException {
input();
pro();
}
static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
deque = new ArrayDeque<Balloon>();
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) {
deque.add(new Balloon(i, Integer.parseInt(st.nextToken())));
}
}
static void pro() {
while (!deque.isEmpty()) {
sb.append(deque.getFirst().idx).append(" ");
int tmp = deque.poll().num;
if (deque.isEmpty()) break;
if (tmp > 0) {
tmp--;
for (int i = 0; i < tmp; i++) {
deque.addLast(deque.pollFirst());
}
} else {
for (int i = 0; i < (-1) * tmp; i++) {
deque.addFirst(deque.pollLast());
}
}
}
System.out.println(sb.toString());
}
}