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 meal i (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 length K(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.
First line of input file contains two integers N (1<=N<=105) and K (1<=K<=N),
followed by a line containing N integers. The ith integer denotes f(i)-the cooking time of
meal number i (1<=f(i)<=109)
Print minimum number of assistans which can cook all the meals in one line.
Input: 5 3 40 30 40 30 40 Output: 3
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.
|Tags||july12, kamranmaharov , simple, sorting|
|Time Limit:||0.261333 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions