Xiao Zhang is often distressed because there are too many things to arrange. Now he has n tasks at hand, and each task has a starting times, and an ending time e ₁. To complete a task, he must do it from the starting time to the ending time, and Xiao Zhang can only perform one task at the same time. Xiao Zhang wants to know how many tasks he can accomplish at most. Input The first line is an integer n (1sns300000), indicating the number of tasks Xiao Zhang has at hand. In the next n lines, each line contains two integers s₁, e. (1ss;

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question
Description
Xiao Zhang is often distressed because there are too many things to arrange. Now he has n tasks at hand, and each task has a starting times, and
an ending time e;. To complete a task, he must do it from the starting time to the ending time, and Xiao Zhang can only perform one task at the
same time.
Xiao Zhang wants to know how many tasks he can accomplish at most.
Input
The first line is an integer n (1sns300000), indicating the number of tasks Xiao Zhang has at hand.
In the next n lines, each line contains two integers s₁, e¡ (1≤s; <e ≤109), indicating the starting time and ending time of the task.
Output
An integer K, indicating at most K tasks Xiao Zhang can complete.
Transcribed Image Text:Description Xiao Zhang is often distressed because there are too many things to arrange. Now he has n tasks at hand, and each task has a starting times, and an ending time e;. To complete a task, he must do it from the starting time to the ending time, and Xiao Zhang can only perform one task at the same time. Xiao Zhang wants to know how many tasks he can accomplish at most. Input The first line is an integer n (1sns300000), indicating the number of tasks Xiao Zhang has at hand. In the next n lines, each line contains two integers s₁, e¡ (1≤s; <e ≤109), indicating the starting time and ending time of the task. Output An integer K, indicating at most K tasks Xiao Zhang can complete.
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr