Skip to content

Instantly share code, notes, and snippets.

@rigibun
Created December 29, 2012 04:27
Show Gist options
  • Save rigibun/4404562 to your computer and use it in GitHub Desktop.
Save rigibun/4404562 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<queue>
using namespace std;
int main(void){
queue<int> a,b,d;
int n, m, k;
cin >> n;
for(int i = 0; i < 2 * n; i++){
d.push(i + 1);
}
cin >> m;
for(int x = 0; x < m; x++){
cin >> k;
if(k == 0){
for(int i = 0; i < n; i++){
a.push(d.front());
d.pop();
}
for(int i = 0; i < n; i++){
b.push(d.front());
d.pop();
}
for(int i = 0; i < n; i++){
d.push(a.front());
a.pop();
d.push(b.front());
b.pop();
}
}
else{
for(int i = 0; i < k; i++){
a.push(d.front());
d.pop();
}
while(!a.empty()){
d.push(a.front());
a.pop();
}
}
}
while(!d.empty()){
cout << d.front() << endl;
d.pop();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment