Wrestling Competition
Time limit1sMemory limit512 MB
Given strengths and a threshold K, count players who could be the last survivor when random pairings are played and a match is decided by strength unless the gap is at most K.
- Level
Medium6 of 10
- Topics
- Sorting, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
A wrestling competition will be held tomorrow. A total of players take part in it. The -th player's strength is .
If the -th player and the -th player have a match, the result depends solely on . If , the player with the higher strength wins. Otherwise, each player has a chance to win.
The competition rules are a little strange. For each match, the referee picks two players uniformly at random from all remaining players and holds a match between them. The loser is eliminated. After matches, the last remaining player is the winner.
Given , , and the array , find how many players have a chance to win the competition.
Input
The first line contains two integers and (, ).
The second line contains integers ().
Output
Print a single line with a single integer: the number of players which have a chance to win the competition.