쉬운 문제였는데, 문제 설명이 난해해 푸는데 오래걸렸다. 요런것도 잘해야겠지...
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int n, k;
int go(vector<pair<int, bool> > con) {
int ans = 0;
int sum = 0;
while (1) {
ans++;
con[n - 1].second = false;
rotate(con.rbegin(), con.rbegin() + 1, con.rend());
con[n - 1].second = false;
for (int i = n-2; i >=0; i--) {
if (con[i].second==true&&con[i + 1].first >= 1 && con[i + 1].second == false) {
con[i + 1].first--;
con[i + 1].second = true;
con[i].second = false;
}
}
con[n - 1].second = false;
if (con[0].first >= 1) {
con[0].first--;
con[0].second = true;
}
sum = 0;
for (int i = 0; i < 2 * n; i++) {
if (con[i].first == 0) sum++;
}
if (sum >= k) return ans;
}
}
int main() {
//freopen("in1.txt", "rt", stdin);
cin >> n >> k;
vector<pair<int, bool> > con(2 * n);
for (int i = 0; i < 2 * n; i++) {
int x;
cin >> x;
con[i].first = x;
con[i].second = false;
}
cout <<go(con) << '\n';
return 0;
}