작성
·
167
0
int main() {
freopen("input.txt", "rt", stdin);
int i, n, k, cnt = 0, pos = 0, total = 0;;
scanf("%d", &n);
vector<int> arr(n);
for (i = 0; i < arr.size(); i++) {
scanf("%d", &arr[i]);
total += arr[i];
}
scanf("%d", &k);
if (total < k) {
printf("-1\n");
return 0;
}
while (1) {
if (arr[pos] > 0) {
arr[pos]--;
cnt++;
}
else {
pos++;
continue;
}
if (cnt == k) {
printf("%d", pos + 1);
break;
}
pos++;
if (pos > n - 1) {
pos = 0;
}
}
}