CPP-Questions-and-Solutions icon indicating copy to clipboard operation
CPP-Questions-and-Solutions copied to clipboard

B. Micro-World

Open Anujkumar2017 opened this issue 3 years ago • 2 comments

Enter your question -

You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.

You know that you have n bacteria in the Petri dish and size of the i-th bacteria is ai. Also you know intergalactic positive integer constant K.

The i-th bacteria can swallow the j-th bacteria if and only if ai>aj and ai≤aj+K. The j-th bacteria disappear, but the i-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria i can swallow any bacteria j if ai>aj and ai≤aj+K. The swallow operations go one after another.

For example, the sequence of bacteria sizes a=[101,53,42,102,101,55,54] and K=1. The one of possible sequences of swallows is: [101,53,42,102,101––––,55,54] → [101,53–––,42,102,55,54] → [101––––,42,102,55,54] → [42,102,55,54–––] → [42,102,55]. In total there are 3 bacteria remained in the Petri dish.

Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.

Enter link to the question(if question belongs to any online platform) -

https://codeforces.com/problemset/problem/990/B

Tags for the question(eg - Array, Basic, Stack, etc.) -

Greedy, Sorting

Anujkumar2017 avatar Oct 05 '21 19:10 Anujkumar2017

@SarthakKeshari Sir, please assign me

Anujkumar2017 avatar Oct 05 '21 19:10 Anujkumar2017

@Anujkumar2017, Kindly add your solution to "codeforces" folder Deadline - 06/10/2021

SarthakKeshari avatar Oct 05 '21 19:10 SarthakKeshari