Disastrous Downtime

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 n 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 1000 milliseconds to process, and it must be processed right away.

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

Input

The first line contains two integers 1 ≤ n ≤ 100 000 and 1 ≤ k ≤ 100 000, the number of upcoming requests and the maximum number of requests per second that each server can handle. Then follow n lines with one integer 0 ≤ ti ≤ 100 000 each, specifying that the ith request will happen ti 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

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

Sample Input 1

2 1

0

1000

Sample Output 1

1

Sample Input 2

3 2

1000

1010

1999

Sample Output 2

2

组队赛的一道题目题意很简单,当时想着用STL什么的做的,HRX小姐姐说有思路就去敲了,很快AC,看了她的代码,思路很巧妙,平常的思路都是按照时间的进行,去看看电脑,考虑电脑,小姐姐的思路是看1s的时间里最多要用到几台电脑,非常神奇,或许这就是大佬吧,贴下代码

#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <stack>
#include <map>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
const int maxn = 100 + 10;
int t[maxn];
int main()
{
    int n,k,x,ans = 0;
    memset(t,0,sizeof(t));
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        t[x/1000]++;
        if(t[x/1000] % k == 0) ans = max(ans,t[x/1000] / k);
        else ans = max(ans,t[x/1000] / k + 1);
    }
    printf("%d\n",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值