https://www.acmicpc.net/problem/20055
구현
문제 조건 그대로 구현하면 되는 문제 .... ㅇㅅㅇ
#include <iostream>
#include <vector>
using namespace std;
int main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N,K;
cin>>N>>K;
vector<int> belt(N*2+1, 0);
vector<bool> isRobot(N*2+1, false);
for(int i=0; i<N*2; i++) cin>>belt[i];
int pos=0;
int level=0;
while(true){
level++;
isRobot[(pos+(N-1))%(N*2)]=false; /// **************
pos--;
if(pos<0) pos=2*N-1;
isRobot[(pos+(N-1))%(N*2)]=false;
for(int i=N-2; i>0; i--){
int tmp = (pos+i)%(N*2);
if(!isRobot[tmp]) continue;
int next = (tmp+1)%(N*2);
if(belt[next]>0 && !isRobot[next]){
isRobot[tmp]=false;
isRobot[next]=true;
belt[next]--;
}
}
if(belt[pos]>0) {
belt[pos]--;
isRobot[pos]=true;
}
int cnt=0;
for(int i=0; i<2*N; i++) {
// cout<<belt[i]<<" ";
if(belt[i]<=0) cnt++;
}
if(cnt>=K) break;
}
cout<<level;
}