Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells
(that is, on a 1 × n table).

At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle
(that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.

After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").

But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".

Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.

Input

The first line of the input contains three integers: nk and a (1 ≤ n, k, a ≤ 2·105)
— the size of the field, the number of the ships and the size of each ship. It is guaranteed that the nk and a are
such that you can put k ships of size a on
the field, so that no two ships intersect or touch each other.

The second line contains integer m (1 ≤ m ≤ n)
— the number of Bob's moves.

The third line contains m distinct integers x1, x2, ..., xm,
where xi is
the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.

Output

Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in
the order the were made. If the sought move doesn't exist, then print "-1".

Sample test(s)
input
11 3 3
5
4 8 6 1 11
output
3
input
5 1 3
2
1 5
output
-1
input
5 1 3
1
3
output

1

这题可以先算出刚开始最大能摆放的木板数,用set维护起点和终点的idx(坐标)和num(即当前空位和下一个空位间最大能放的木板数),用sum记录总共能放的木板数。每次更新一个坐标a,找到和当前要更新的点最近的右边一点坐标b,然后更新当前点a的num和这一点左边b-1的num,然后重新调整sum,如果sum<k,那么这点就是答案,否则把a放入set里.

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define maxn 200050
struct node{
int num,idx;
}a,temp1,temp2,b1,b2;
int b[maxn];
bool operator <(node a,node b){
return a.idx<b.idx;
}
set<node>myset;
set<node>::iterator it; int shumu(int l,int m)
{
int i,j,num,sheng;
num=l/(m+1);
sheng=l%(m+1);
if(sheng==m)num++;
return num;
} int main()
{
int n,m,k,i,j,h,num,flag,cnt;
while(scanf("%d%d%d",&n,&k,&m)!=EOF)
{
myset.clear();
num=shumu(n,m);
a.idx=0;a.num=num;
myset.insert(a);
a.idx=n+1;a.num=0;
myset.insert(a); scanf("%d",&h);
for(i=1;i<=h;i++){
scanf("%d",&b[i]);
}
flag=1;cnt=0;
for(i=1;i<=h;i++){
a.idx=b[i];a.num=0;
it=myset.lower_bound(a);
temp2=*it;
it--;
temp1=*it;
num-=temp1.num; b1.idx=temp1.idx;b1.num=shumu(b[i]-temp1.idx-1,m);
b2.idx=b[i];b2.num=shumu(temp2.idx-b[i]-1,m);
num+=b1.num+b2.num;
if(num<k){
flag=0;cnt=i;break;
}
myset.erase(temp1);
myset.insert(b1);
myset.insert(b2);
}
if(flag==0){
printf("%d\n",i);continue;
}
else printf("-1\n");
}
return 0;
}

Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships的更多相关文章

  1. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  2. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  3. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set乱搞

    D. One-Dimensional Battle ShipsTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  4. Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解

    D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  5. Codeforces Round #Pi (Div. 2)(A,B,C,D)

    A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #i ...

  6. codeforces Round #Pi (div.2) 567ABCD

    567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...

  7. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. Codeforces Round #Pi (Div. 2) B. Berland National Library set

    B. Berland National LibraryTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  9. Codeforces Round #Pi (Div. 2) A. Lineland Mail 水

    A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...

  10. Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥

    题目链接: http://codeforces.com/contest/567/problem/E 题意: 给你一个带重边的图,求三类边: 在最短路构成的DAG图中,哪些边是必须经过的: 其他的(包括 ...

随机推荐

  1. spring boot下为配置属性值加密的正确姿势

    最近做电商系统,安全性要求比较高,针对配置属性值的加密自然也是需要增强的点之一,那么如何加密呢? 网上搜索了些,有jasypt加密mysql密码的最为普遍,可惜问题就在于只能加密mysql信息,其他的 ...

  2. 【ASM】查看ASM磁盘组剩余容量和总容量

    col total_size for a10; col free_size for a20; select name,total_mb/1024 || 'G' as total_size , free ...

  3. XSS - Labs 靶场笔记(上)

    上周在网上看到的一个XSS平台,刷一波<doge Less - 1: 1.进入主界面,由图二可知是GET请求,提交name=test,回显在页面 2.查看源代码可知 没有做任何过滤,显然存在反射 ...

  4. 记忆中的像素块褪色了吗?用开源的体素编辑器重新做个 3D 的吧!

    本文适合对图形表现有兴趣的美术或者开发人员 本文作者:HelloGitHub-Joey 早期的的显示设备像素颗粒较大,使得显示内容的颗粒感严重,像是由一堆方块组成的.比较好的例子就是 GBA 上的游戏 ...

  5. BAPI创建PO,禁止净价信息更新

    大家都知道创建PO时,我们如果勾选了"信息更新",则该PO保存后相应的信息记录会把这个PO更新为其最后的凭证,那么这张PO的净价会作为下次创建新PO时净价的默认值. 这样我们设置的 ...

  6. Pytorch入门——手把手教你MNIST手写数字识别

    MNIST手写数字识别教程 要开始带组内的小朋友了,特意出一个Pytorch教程来指导一下 [!] 这里是实战教程,默认读者已经学会了部分深度学习原理,若有不懂的地方可以先停下来查查资料 目录 MNI ...

  7. 2021年首届.NET线下沙龙上海站 - 2021 .NET Meetup in Shanghai

    .NET Conf 2020 刚刚在苏州落下帷幕, .NET 开发者们的热情不减,来自五湖四海的朋友一起参加疫情之下的 .NET 盛会. 2021年上海第一场线下活动就要来了,快来加入我们一起学习.N ...

  8. 1、kubernetes简介

    Kubernetes简介 文档信息 中文官网:https://kubernetes.io/zh 中文社区:https://www.kubernetes.org.cn/ Kubernetes是容器集群管 ...

  9. html简单基础

    标签语法 标签的语法: <标签名 属性1="属性值1" 属性2="属性值2"-->内容部分</标签名> <标签名 属性1=&quo ...

  10. STL_list容器

    一.List简介 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的. 链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每 ...