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. (转)linux dumpe2fs命令

    linux dumpe2fs命令 命令名称 dumpe2fs - 显示ext2/ext3/ext4文件系统信息. dumpe2fs命令语法 dumpe2fs [ -bfhixV ] [ -o supe ...

  2. linux网卡软中断shell脚本

    LANG=C;export LANG;  service irqbalance stop >/dev/null 2>&1;chkconfig irqbalance off; bon ...

  3. LCD1602显示中文汉字

    小子在西藏 2011-11-25编写 特别说明笔者是上面的作者,感谢那些原意分享知识的人.时隔5年我又看到了笔者当年写的东西,我想这期间还有许许多多的人 今天写在博客上,愿更多后来者可以学习. LCD ...

  4. 常用的http网页错误代码表---------495引发的一个简单到爆,但基于国内环境只能呵呵呵的血案

    敲代码敲出了个网页错误代码 495. 然后,正常的跑去百度,看了一堆还是没有完整的网页错误代码,应该说国内的环境的网页错误代码表只有官方的那几个,那么只能FQ了. 去到谷歌,一查全是俄语,乐了,明白是 ...

  5. 写TXT文件

    #region 写日志 private static void writelog(string strwrite) { string strPath = "d:/log.txt"; ...

  6. Canvas基本绘画学习

    学好Canvas,从简单开始.下面是一些Canvas入门最基本的实例分享: <!DOCTYPE html> <html> <head lang="en" ...

  7. 【简抄】h5 新增的几个背景属性和文本属性

    一.背景图像显示: ①background-size:规定背景图像的大小: 值:像素值.百分比.auto.cover.contain ②background-origin :规定背景图像的起始位置: ...

  8. Linux生产服务器常规分区方案

    常规分区方案 / 剩余硬盘大小 swap 100M /boot 100M DB及存储:有大量重要的数据 /data/ 剩余硬盘大小 / 50-200GB swap 1.5倍 /boot 100MB 门 ...

  9. jsp另外五大内置对象之out输出

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  10. UWP开发:存储容器设置&复合设置数据

    有时候为了将应用设置进行分类,需要创建新的容器进行存储应用设置的信息. 1,容器的创建:在一个根容器里嵌套一个新容器 1)首先获取根容器. 2)调用ApplicationDataContainer.C ...