J. Killing everything
time limit per test

4 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

There are many enemies in the world such as red coders and hackers. You are trying eliminate everybody. Everybody is standing on a road, which is separated into 109 sections. The sections are numbered 1, 2, 3, 4, …109 from west to east. You want to kill N enemies. The ith enemy will be standing on the section Ai. In order to kill the enemies, you prepared P small bombs and Q large bombs. You can choose a positive integer w as a parameter for energy consumption. Then, a small bomb can kill all enemies in at most w consecutive sections, and a large bomb can kill all enemies of at most 2w consecutive sections.

Enemies can be killed by more than one bomb. You want to kill all enemies. Since it is expected that many civilians will walk down that road, for the sake of safety, you have to fix the positions of the bombs and minimize the value of w.

So you decided to Write a program that, given information of the enemies and the number of bombs, determine the minimum value of w so all enemies can be killed.

Input

The input consists of several test cases, the first line contains the number of test cases T. For each test case: The first line of input contains three space separated integers N, P, Q (1 ≤ N ≤ 2000, 0 ≤ P ≤ 105, 0 ≤ Q ≤ 105), where N is the number of the enemies, P is the number of small bombs, and Q is the number of large bombs.

The ith line (1 ≤ i ≤ N) of the following N lines contains an integer Ai, the section where the ith enemy will be standing.

Output

Output: For each test cases print the solution of the problem on a new line.

Examples
input
  1. 1
    3 1 1
    2
    11
    17
output
  1. 4
Note

In the sample test case you have 3 enemies at positions: 2, 11, 17.

For w = 4, one possible solution is to throw one small bomb on segment 1 - 4, and one large bomb on segment 11 - 18. This configuration will kill all three enemies.

There is no configuration with w < 4 that can kill them all.

题意:给你n个位置,p个小炸弹,q个大炸弹;小炸弹可以连续炸w长度,大炸弹可以连续炸2*w长度

思路:显然二分答案求最小的w,问题在于如何check;

   dp[i][j]表示炸完i之前所有点,使用j个小炸弹,最少需要多少个大炸弹;

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. #include<bitset>
  15. #include<time.h>
  16. using namespace std;
  17. #define LL long long
  18. #define pi (4*atan(1.0))
  19. #define eps 1e-4
  20. #define bug(x) cout<<"bug"<<x<<endl;
  21. const int N=2e3+,M=5e5+,inf=1e9+,mod=1e9+;
  22. const LL INF=1e18+,MOD=1e9+;
  23.  
  24. int n,p,q;
  25. int nex[N][];
  26. int dp[N][N],a[N];
  27. int check(int x)
  28. {
  29. for(int i=;i<=n;i++)
  30. {
  31. nex[i][]=lower_bound(a+,a+n+,a[i]+x)-a;
  32. if(*x-inf+a[i]>)nex[i][]=n+;
  33. else nex[i][]=lower_bound(a+,a+n+,a[i]+x+x)-a;
  34. }
  35. for(int i=;i<=n+;i++)
  36. {
  37. for(int j=;j<=p;j++)
  38. dp[i][j]=inf;
  39. }
  40. dp[][]=;
  41. for(int i=;i<=n;i++)
  42. {
  43. for(int j=;j<=p;j++)
  44. {
  45. int v=nex[i][];
  46. dp[v][j+]=min(dp[v][j+],dp[i][j]);
  47. v=nex[i][];
  48. dp[v][j]=min(dp[v][j],dp[i][j]+);
  49. }
  50. }
  51. for(int i=;i<=p;i++)
  52. if(dp[n+][i]<=q)return ;
  53. return ;
  54. }
  55. int main()
  56. {
  57. int T,cas=;
  58. scanf("%d",&T);
  59. while(T--)
  60. {
  61. scanf("%d%d%d",&n,&p,&q);
  62. for(int i=;i<=n;i++)
  63. scanf("%d",&a[i]);
  64. if(p+q>=n)
  65. {
  66. printf("1\n");
  67. continue;
  68. }
  69. sort(a+,a++n);
  70. a[n+]=inf*;
  71. int s=;
  72. int e=inf,ans=-;
  73. while(s<=e)
  74. {
  75. int mid=(s+e)>>;
  76. //cout<<mid<<endl;
  77. if(check(mid))
  78. e=mid-,ans=mid;
  79. else s=mid+;
  80. }
  81. printf("%d\n",ans);
  82. }
  83. return ;
  84. }

codeforces gym 100947 J. Killing everything dp+二分的更多相关文章

  1. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  2. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  3. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

  4. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

  5. codeforces Gym 100187J J. Deck Shuffling dfs

    J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  6. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  7. codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径

    题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...

  8. codeforces Gym 100500 J. Bye Bye Russia

    Problem J. Bye Bye RussiaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1005 ...

  9. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

随机推荐

  1. Autel Maxisys MS908CV Description

    The new Autel MaxiSys CV Heavy Duty Diagnostic is built on the powerful MaxiSys 908 platform and pro ...

  2. The Little Prince-11/28

    The Little Prince-11/28 Today I find some beautiful words from the book. You know -- one loves the s ...

  3. 巧用ELK快速实现网站流量监控可视化

    前言 本文可能不会详细记录每一步实现的过程,但一定程度上可以引领小伙伴走向更开阔的视野,串联每个环节,呈现予你不一样的效果. 业务规模 8个平台 100+台服务器 10+个集群分组 微服务600+ 用 ...

  4. HTML的简介

    1.HTML语言是做显示用的.HTML文件由浏览器来转译执行.(全站工程师:全都会.) 2.静态网页由HTML(显示).CSS(修饰).JAVAScript(简单交互)三种元素构成.3.动态网页:数据 ...

  5. ubuntu 构建Xilinx交叉编译环境

    嵌入式系统软硬件协同设计实战指南_基于XILINX ZYNQ_13603826.pdf 202页

  6. everything不显示移动硬盘中路径

    点击他的设置选项,里面有NTFS,移除那些硬盘就可以了.

  7. shell 中的小技巧

    去掉最后一个字符 sed 's/.$//' awk '{sub(/.$/,"")}1' awk '{printf $0"\b \n"}' [root@ ~]# ...

  8. WEB后台认证机制

    mark to :http://www.cnblogs.com/xiekeli/p/5607107.html HTTP Basic Auth HTTP Basic Auth简单点说明就是每次请求API ...

  9. 基于ZooKeeper和Thrift构建动态RPC调用

    一.基本功能 实现服务端向ZooKeeper集群注册自己提供的服务,并且把自己的IP地址和服务端口创建到具体的服务目录下.客户端向ZooKeeper集群监听自己关注的RPC服务(例如:sayHello ...

  10. python识别图片生成字符模式

    此python文件来自D7哥, 放在这里备份. 用法 python3 PIL\&argparse.py 1.jpg -o test.txt --width 300 --height 300 p ...