An astronomy club has n stargazers, ranked 0 through n-1. Over a season, stargazers log constellation sightings; each log entry records which stargazer made it and which constellation type they saw. A stargazer earns a rank-up if there exists at least one constellation type for which the number of sightings that stargazer logged of that exact type is strictly greater than the stargazer's own rank number. (In particular, rank 0 earns a rank-up as soon as they log even a single sighting of any type, since any positive count is strictly greater than 0.) Count how many of the n stargazers earn a rank-up.
Line 1: two integers n m — the number of stargazers and the number of log entries.
Each of the next m lines contains two integers s t — stargazer index s (0-indexed) logged one sighting of constellation type t.
A single integer: the number of stargazers who earn a rank-up.
Example 1
Input
3 5 0 1 1 2 1 2 2 5 2 5
Expected
2
Explanation
Stargazer 0 logged 1 sighting of type 1 (1 > 0, rank-up). Stargazer 1 logged 2 sightings of type 2 (2 > 1, rank-up). Stargazer 2 logged 2 sightings of type 5, but 2 is not > 2, so no rank-up. Total rank-ups = 2.
Example 2
Input
4 6 0 3 1 4 1 4 2 0 2 0 3 7
Expected
2
Explanation
Stargazer 0: 1 sighting of type 3 (1>0, rank-up). Stargazer 1: 2 sightings of type 4 (2>1, rank-up). Stargazer 2: 2 sightings of type 0, but 2 is not >2, no rank-up. Stargazer 3: 1 sighting of type 7, but 1 is not >3, no rank-up. Total rank-ups = 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →