You're investigating what happened when one of your computer systems recently broke down. So far you've concluded that the system was overloaded; it looks like it couldn't handle the hailstorm of incoming requests. Since the incident, you have had ample opportunity to add more servers to your system, which would make it capable of handling more concurrent requests. However, you've simply been too lazy to do it—until now. Indeed, you shall add all the necessary servers . . . very soon!

To predict future requests to your system, you've reached out to the customers of your service, asking them for details on how they will use it in the near future. The response has been pretty impressive; your customers have sent you a list of the exact timestamp of every request they will ever make!

You have produced a list of all the nn upcoming requests specified in milliseconds. Whenever a request comes in, it will immediately be sent to one of your servers. A request will take exactly 10001000 milliseconds to process, and it must be processed right away.

Each server can work on at most kk requests simultaneously. Given this limitation, can you calculate the minimum number of servers needed to prevent another system breakdown?

Input Format

The first line contains two integers 1 \le n \le 100 0001≤n≤100000 and 1 \le k \le 100 0001≤k≤100000, the number of upcoming requests and the maximum number of requests per second that each server can handle.

Then follow nn lines with one integer 0 \le t_i \le 100 0000≤ti​≤100000 each, specifying that the ii-th request will happen t_iti​milliseconds from the exact moment you notified your customers. The timestamps are sorted in chronological order. It is possible that several requests come in at the same time.

Output Format

Output a single integer on a single line: the minimum number of servers required to process all the incoming requests, without another system breakdown.

样例输入1

2 1
0
1000

样例输出1

1

样例输入2

3 2
1000
1010
1999

样例输出2

2

题目来源

Nordic Collegiate Programming Contest 2015​

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
const int N=1e5+;
int t[N];
int n,k;
int MAX,ans; //举个例子
// n=7 k=3
// 1000 1010 1090 2000 2080 2089 3010
// 3 3 4 3 3 2 1
// 1 1 2

int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%d",&t[i]);
MAX=;
int i,j;
for(i=,j=;i<n&&j<n;)
{
while(t[j]-t[i]<&&j<n) j++;
if(j==n) break;
MAX=max(MAX,j-i);//一秒应该处理的请求数目,大于k时,1个机器就不够了。
i++;
}
MAX=max(MAX,j-i);
ans=MAX/k;
if(MAX%k) ans++;//不能整除就必须要在加一个。
printf("%d\n",ans);
return ;
}

Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime的更多相关文章

  1. Nordic Collegiate Programming Contest 2015​ B. Bell Ringing

    Method ringing is used to ring bells in churches, particularly in England. Suppose there are 6 bells ...

  2. Nordic Collegiate Programming Contest 2015​ G. Goblin Garden Guards

    In an unprecedented turn of events, goblins recently launched an invasion against the Nedewsian city ...

  3. Nordic Collegiate Programming Contest 2015​ E. Entertainment Box

    Ada, Bertrand and Charles often argue over which TV shows to watch, and to avoid some of their fight ...

  4. Nordic Collegiate Programming Contest 2015​(第七场)

    A:Adjoin the Networks One day your boss explains to you that he has a bunch of computer networks tha ...

  5. (寒假GYM开黑)2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)

    layout: post title: 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) author: &qu ...

  6. German Collegiate Programming Contest 2015 计蒜课

    // Change of Scenery 1 #include <iostream> #include <cstdio> #include <algorithm> ...

  7. Codeforces Gym101572 B.Best Relay Team (2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017))

    2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) 今日份的训练,题目难度4颗星,心态被打崩了,会的算法太少了,知 ...

  8. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)- D. Delivery Delays -二分+最短路+枚举 ...

  9. 2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp

    2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)-E. Explosion Exploit-概率+状压dp [P ...

随机推荐

  1. HDU 5875 H - Function 用单调栈水过了

    http://acm.hdu.edu.cn/showproblem.php?pid=5875 单调栈,预处理to[i]表示第一个比a[i]小的数字,一直跳就可以. 这题是数据水而已. 这里学习下单调栈 ...

  2. android pm命令

    把网络apk下载到盒子或者其他安卓设备上 1.adb push windows的原路径 android设备的路径 2.pm install android设备的路径 注意:这里pm命令是安卓设备才有的 ...

  3. 设置Cookie最大存活时间

    Cookie和Session都是由Tomcat自动创建的对象,Cookie的默认最大存活时间是 -1 ,即当浏览器关闭时Cookie就消失了:Session的默认最大存活时间是30分钟. 使用Sess ...

  4. UNITY_MATRIX_MVP和UnityObjectToClipPos

    在unity5.6以上版本中,shader中的UNITY_MATRIX_MVP将会被UnityObjectToClipPos替代,以后我们在写顶点函数时就是这样的 v2f vert(appdata v ...

  5. uvm_reg_predictor——寄存器模型(十七)

    这是寄存器模型类中唯一派生自uvm_component的类,我们的寄存器模式需要实时,以最接近的方式知道DUT中寄存器的变化,uvm_reg_predictor就是为这个而生的. // TITLE: ...

  6. hiho一下 第四十四周 博弈游戏·Nim游戏(直接公式解)

    证明看这http://hihocoder.com/contest/hiho44/problem/1 思路: 设 sg=a[1]^a[2]^...a[n],若sg=0,则先手Alice必败,否则必赢. ...

  7. Page_Load与sender -- PostBack是由哪个 ASP.NET控件引起 ?

    Page_Load与sender -- PostBack是由哪个 ASP.NET控件引起 ? 之前有讨论过ASP.NET Web Form "事件"里面的 "sender ...

  8. UVA 818 Cutting Chains 切断圆环链 (暴力dfs)

    题意就是给一张无向图,去掉某些结点,然后连成一条链,问最少去掉几个结点. n很小n<=15,所以直接枚举2^15个状态就行啦. 链的条件是1.无环,2.没有度大于2的点,3.把n个散链连起来需要 ...

  9. 如何使用Python生成200个优惠券(激活码)

    解析: 常见的优惠券(激活码)是由数字.字母(大小写)组成: string.ascii_letters   26个大小写字母: string.digits 0-9数字: 随机组合 使用random.s ...

  10. Hive相关集锦

    Hive介绍 http://www.cnblogs.com/sharpxiajun/archive/2013/06/02/3114180.htmlHive的数据类型和数据模型 http://www.c ...