#K92422. Maximum Non-Overlapping Talks Scheduling
Maximum Non-Overlapping Talks Scheduling
Maximum Non-Overlapping Talks Scheduling
You are given a set of talks, each represented by a starting time and an ending time. Your task is to select the maximum number of talks such that no two selected talks overlap. Two talks are considered non-overlapping if the start time of the current talk is (\geq) the end time of the previous talk. Formally, given two arrays (S = [s_1, s_2, \dots, s_n]) and (E = [e_1, e_2, \dots, e_n]) where (s_i) and (e_i) denote the start and end times of the (i)-th talk, you need to maximize the count of talks chosen such that for any two consecutive talks (i) and (j) in the selection, (s_j \geq e_i). This problem can be efficiently solved using a greedy approach that runs in (O(n \log n)) time.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n), representing the number of talks. The second line contains (n) space-separated integers, representing the start times. The third line contains (n) space-separated integers, representing the end times.
outputFormat
Output to standard output (stdout) a single integer representing the maximum number of non-overlapping talks that can be scheduled.## sample
4
1 2 4 6
3 5 7 9
2
</p>