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. MoinMoin install in apache (win)

    一:下载环境 xampp:http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/1.8.1/xampp-win32-1.8.1-VC9 ...

  2. [转]Todd.log - a place to keep my thoughts on programming 分布式架构中的幂等性

    Todd.log - a place to keep my thoughts on programming 理解HTTP幂等性 基于HTTP协议的Web API是时下最为流行的一种分布式服务提供方式. ...

  3. More than one fragment with the name [spring_web] was found. This is not legal ...

    今天在搭建springweb应用环境的时候启动tomcat报错More than one fragment with the name [spring_web] was found. This is ...

  4. java的三大特性之一封装概述

    属性: 属性static属性//静态成员变量/类变量 属性 //实例变量 普通成员变量 类变量,类方法 类变量是所有对象共享的变量,任何一个该类的对象去访问它时,取到的都是同一个值,同样任何一个变量去 ...

  5. spring data jpa自定义baseRepository

    在一些特殊时候,我们会设计到对Spring Data JPA中的方法进行重新实现,这将会面临一个问题,如果我们新创建一个实现类.如果这个实现类实现了JpaRepository接口,这样我们不得不实现该 ...

  6. 只用jsp实现同样的Servlet功能

    Jsp最终都会转化成java形式的Servlet执行,因此也可以说Jsp的本质就是Servlet,在jsp执行后,会在服务器上(例如tomcat中)生成.java以及.class文件.具体执行过程如下 ...

  7. AngularJS(七):表单-单选框、下拉列表

    本文也同步发表在我的公众号“我的天空” 单选框 在AngulerJS中单选框的处理与复选框有不少相似之处,我们来看以下示例: <body ng-app="myApp" ng- ...

  8. DHTMLX 使用汇总

    1.dhtmlxGrid  底部总出现滚动条 ------------------------------------------ 发现使用DHTMLXGRID时 GRID 底边总有   滚动条 测试 ...

  9. springboot 2.0 Redis command timed out的解决

    环境:springboot 2.0.7 spring data redis springboot从1.x升级到2.x后,spring data redis使用的redis客户端驱动从1.x的jedis ...

  10. 设置DIV随滚动条滚动而滚动

    有段时间没有碰Web端了,最近做了个功能,需要做个DIV随滚动条滚动而滚动,mark一下: 源码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...