Problems > Attend the Most Events

Attend the Most Events

Difficulty: 1800 5000 ms 128 MB

greedy heap

Each event spans days [start, end] and you can attend one event per day (any day within its span). Maximize the number of events attended.

Input: the first line has N; each of the next N lines has an event's start and end day.

Output: the maximum number of events attendable.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ start ≤ end ≤ 105

Sample Tests

Input 1
3
1 2
2 3
3 4
Output 1
3
Input 2
2
1 1
1 1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.