output

standard output

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: n, k 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 n, k 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".

Examples

Input

Copy

11 3 3
5
4 8 6 1 11

Output

Copy

3

Input

Copy

5 1 3
2
1 5

Output

Copy

-1

Input

Copy

5 1 3
1
3

Output

Copy

1

题意:

给你一艘船的长度和船的数量,每一艘船至少格一个空格,然后再给你m个查询,问在第几个查询出错了。

思路:

很明显二分,至于怎样二分,其实解题无非迭代或递归,一般二分都是迭代解题,故假设如果这n个查询是有序的,这就很好处理了,故我们先排一个序,再迭代就行。

code:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n, k, a,m;
struct node {int x;int id;
}arr[200100];
bool cmp(node a, node b)
{return a.x < b.x;
}
void input()
{cin >> n >> k >> a;cin >> m;for (int i = 1; i <= m; i++){cin >> arr[i].x;arr[i].id = i;}sort(arr + 1, arr + 1 + m, cmp);
}
bool pang(int l)
{int can = 0, yu = 0;for (int i = 1; i <= m; i++){if (arr[i].id <= l){can += (arr[i].x - yu) / (a+1);yu = arr[i].x;}}can += (n - yu+1) / (a + 1);if (can >= k)return 1;elsereturn 0;
}
int solve()
{int l = 1, r = m,ans=0;while (l <= r){int mid = (l + r) / 2;if (pang(mid)){ans = mid;l = mid+1;}else{r = mid - 1;}}return ans;
}
int main()
{input();int ans=solve();if (ans == m)cout << -1 << endl;elsecout << ans + 1 << endl;return 0;
}

D. One-Dimensional Battle Ships相关推荐

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

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

  2. One-Dimensional Battle Ships CodeForces - 567D

    lice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line ...

  3. 【 HDU - 5093】Battle ships(匈牙利算法,二分图匹配)

    题干: Dear contestant, now you are an excellent navy commander, who is responsible of a tough mission ...

  4. 51 nod 1521 一维战舰 时间复杂度O(n),同 Codeforces 567D. One-Dimensional Battle Ships 有详细注释

    题目:51nod: 题目Codeforces: 题目注意到两个战舰不能挨在一起就可以了. // 每一段 struct node{int left; // 段的左端点int right; // 段的右端 ...

  5. 51 nod 1521 一维战舰 时间复杂度O(n),同 Codeforces 567D. One-Dimensional Battle Ships 有详细注释...

    题目:51nod: 题目Codeforces: 题目注意到两个战舰不能挨在一起就可以了. // 每一段 struct node{int left; // 段的左端点int right; // 段的右端 ...

  6. HDU 5093 Battle ships(二分图最大匹配)

    题意:一个m行n列的图由#.*.o三种符号组成,分别代表冰山.海域.浮冰,问最多可放的炮舰数(要求满足以下条件) 1.炮舰只可放在海域处 2.两个炮舰不能放在同一行或同一列(除非中间隔着一个或多个冰山 ...

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

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

  8. 2014_shanghai_visit

    5090 Game with Pearls 签到题目,直接模拟即可. 5091 Beam Cannon 矩形覆盖的最大点数,离散化+扫描线+线段树. 5092 Seam Carving 记录路径的DA ...

  9. 动态规划 —— 背包问题

    [概述] 背包问题(Knapsack problem)是一种组合优化的NP完全问题. 问题可以描述为:给定一组物品,每种物品都有自己的重量和价格,在限定的总重量内,我们如何选择,才能使得物品的总价格最 ...

最新文章

  1. opencv 1 图像载入、显示和输出
  2. js调用数科阅读器_阅读大型 JavaScript 源码时有什么好用的工具?
  3. 神经网络迭代次数与Lambert定律
  4. 04.Java网络编程(转载)
  5. 利用银行家算法避免死锁(C++实现)
  6. oracle 性别 函数索引优化,oracle优化记录4_改写函数索引列
  7. RabbitMQ fanout交换机(消费者)
  8. virtualpc设置共享文件夹
  9. 单片机小白学步系列(一) 单片机的前世今生
  10. 记录一种多个按钮中每次只能选中一个的实现方式
  11. c语言宏 转换字符串,c预处理程序-如何从C宏的值生成char字符串?
  12. 连Spring源码都没看过,你怎么敢在简历上写“精通”?
  13. 我为何选择Facebook广告
  14. Atitit.跨语言数据库db  api兼容性 jdbc odbc ado oledb 增强方案
  15. 学习C语言必须掌握的10个经典的C语言小程序
  16. 高等代数第3版下 [丘维声 著] 2015年版_全国硕士研究生入学统一考试管理类联考综合能力考试大纲(2021年版)...
  17. python 白盒测试_白盒测试方法
  18. 知了课堂python_Python框架Flask系列课程(2)—全栈开发[知了课堂]
  19. 【海康威视】WPF客户端二次开发:【1】监控视频画面预览(SDK初始化、设备登录、监控画面预览)
  20. 打开PDF时显示please wait...怎么办?没有安装pdf阅读器经常出现的提示信息

热门文章

  1. 佳博打印机 ANDROID
  2. 中高级前端必须注意的40条移动端H5坑位指南
  3. <吃掉那只青蛙>读后感
  4. R.E.管理器Root Explorer v2.21.1汉化版
  5. 网站要如何发外链?目前可以发外链的网站有哪些?
  6. VMvare克隆虚拟机及网卡问题
  7. mysql n8_mysql几种引擎和使用场景
  8. How to use HM software(H.265)
  9. python 第一行输入n表示一天中有多少人买水果_python 浙大-MOOC-PTA ch4
  10. JavaScript交互式网页设计 • 【第1章 JavaScript 基本语法】