You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
754 B
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, a, m, ans = -1;
scanf("%d%d%d%d", &n, &k, &a, &m);
auto calc = [&a](auto l, auto r) { return (r - l + 2) / (a + 1); };
set<pair<int, int>> s({{n, 1}});
int ships = calc(1, n);
for (int i = 1, x; i <= m && ans == -1; i++)
{
scanf("%d", &x);
auto [r, l] = *s.lower_bound({x, -1});
s.erase({r, l}), ships -= calc(l, r);
if (l < x) s.insert({x - 1, l}), ships += calc(l, x - 1);
if (x < r) s.insert({r, x + 1}), ships += calc(x + 1, r);
if (ships < k) ans = i;
}
printf("%d", ans);
return 0;
}