裸二分
#include#include #include #include #include #include #include #include #include using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i =0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (200000+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int n,k,a,m;int x[MAXN],x2[MAXN];bool check(int m){ For(i,m) x2[i]=x[i]; sort(x2+1,x2+1+m); int l=1,tot=0; For(i,m) { int len=x2[i]-l+1; tot+=len/(a+1); l=x2[i]+1; } tot+=(n+1-l+1)/(a+1); if (tot>=k) return 1; return 0;}int main(){// freopen("D.in","r",stdin);// freopen(".out","w",stdout); cin>>n>>k>>a>>m; For(i,m) scanf("%d",&x[i]); int l=1,r=m,ans=INF; while(l<=r) { int m=(r+l)/2; if (check(m)) l=m+1; else r=m-1,ans=min(ans,m); } if (ans==INF) ans=-1; cout< <