/
2346.cpp
48 lines (40 loc) · 918 Bytes
/
2346.cpp
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
#include <iostream>
#include <queue>
#include <deque>
using namespace std;
deque<pair<int, int>> q;
pair<int, int>p;
int N;
int main(){
cin>>N;
for(int i=1;i<=N;i++){
int a;
cin>>a;
q.push_back(make_pair(i, a));
}
int pos=0, target, a;
p = q.front();
q.pop_front();
cout<<p.first;
target=p.second;
while(!q.empty()){
pos=0;
if(target>0){
while(++pos < target){
p = q.front(); q.pop_front();
q.push_back(p);
}
p = q.front(); q.pop_front();
}
else {
while(--pos > target){
p = q.back(); q.pop_back();
q.push_front(p);
}
p = q.back(); q.pop_back();
}
a = p.first;
target = p.second;
cout<<" "<<a;
}
}