report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Brewing potion 2 - MarisaOJ: Marisa Online Judge

Brewing potion 2

Time limit: 1000 ms
Memory limit: 256 MB
Marisa has $n$ mushrooms, $i^{th}$ mushroom weigh $A_i$. Today she wants to make a potion bottle. She can use an arbitrary numbers of mushrooms in a potion bottle but two mushrooms that differ in weight by more than $k$ cannot be used in the same potion bottle. What is the maximum number of mushrooms that can be used to make one potion bottle? (Marisa wants her potion to be as strong as possible). ### Input - The first line contains two integers $n,k$. - The second line contains $n$ integers $A_i$. ### Output - The maximum number of mushrooms can be used. ### Constraints - $1 \le n \le 10^5$. - $1 \le k,A_i \le 10^9$ ### Example Input: ``` 6 6 1 2 5 7 9 10 ``` Output: ``` 4 ```
Introduction to two pointers
Merge array
Brewing potion 2
Unique elements
Small range
Number of pairs
Sum of three values
Brewing potion 3
Brewing potion 4
Three sequences
Biggest submatrix
Choosing numbers
Topic
Two pointers
Rating 800
Solution (0) Solution