codechef july月赛 Chef's Dream

来源:互联网 发布:java精品课程网站 编辑:程序博客网 时间:2024/05/21 12:43

Chef's Dream

Problem code: DREAM

  • My Submissions
  • All Submissions

All submissions for this problem are available.

The Chef is sleeping now. He tries to cook new kind of meals in his dream.

These meals are arranged in a row and numbered from 1 to N consecutively. For each meali (1<=i<=N) there is given one integer f(i) which denotes the time needed to cook it. Initially, all meals are uncooked. Each assistant of The Chef (there are infinite number of them) can help him with cooking.

The abilities of all assistants are same. There can be at most one assistant cooking at each moment. He must choose some continuous subsequence of meals with lengthK(any such subsequence can be chosen). And if there are uncooked meals in it, he will cook all uncooked meals which has the minimum cooking time among uncooked meals in the chosen subsequence. Nothing done to another meals.

The dream was so interesting that he tried to solve such a problem: What is the minimum number of assistants which can cook all the meals assuming that each of them will cook at most once? But since the bell rings and Chef's friends has come to visit him, he will wake up after 2 seconds. Your program should calculate the answer before The Chef will come to himself.

Input

First line of input file contains two integers N (1<=N<=105) andK (1<=K<=N), followed by a line containingN integers. The ith integer denotes f(i)-the cooking time of meal numberi (1<=f(i)<=109)

Output

Print minimum number of assistans which can cook all the meals in one line.

Example

Input:5 340 30 40 30 40Output:3

Explanation:
3 assistants are enough to cook all the meals. They can work in following schedule:
1st assistant chooses interval [2,4] and cooks meals 2 and 4.
2nd assistant chooses interval [1,3] and cooks meals 1 and 3.
3rd assistant chooses interval [3,5] and cooks meal 5.

Other schedules can also be possible.


题意:   输入n  k  n个数  区间长度k

然后每次在区间内把最小的数标记  问所有的都标记后要多少次


/*我一开始拿到这道题 手无足措不知道该如何下手  这种题千万注意 一定要多写几组数据 认真研究如果多写几组数据就会发现如下规律*/#include <iostream>#include <map>#include <cstdio>using namespace std;const int sz=200200;int B[sz],N,K,ans;map<int,bool> hm;int main(){int f;scanf("%d%d",&N,&K);for(int i=1;i<=N;i++){scanf("%d",&f);if(!hm[f])//超级帅 把复杂度降低到了log(n),方法很巧妙{hm[f]=true; ans++; B[i+K-1]=f;}hm[B[i]]=false;}for(i=1;i<=N;i++) printf("%d\n",B[i]);printf("%d\n",ans);return 0;}



原创粉丝点击