Embercode
✕
Greedy AlgorithmsCoding problems

Greedy Algorithms: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 7 solved

  • A conference has one stage. Each talk is booked as a time window [start, finish): it begins at start and ends just before finish. Two talks clash when their windows overlap. A talk that begins at the exact moment another one ends does not clash with it.

    The organiser wants the stage to show as many talks as possible. Print that largest number.

    **Constraints:** 1 <= n <= 100000. 0 <= start < finish <= 1000000000.

    Input. The first line holds n. Each of the next n lines holds two integers: start and finish.

    Output. One integer: the largest number of talks that can be shown without a clash.

    Example 1 input

    4
    1 5
    4 6
    5 9
    0 10
    

    Output

    2
    

    Example 2 input

    3
    1 3
    3 5
    2 4
    

    Output

    2