#K216. Task Allocation Problem

    ID: 24675 Type: Default 1000ms 256MiB

Task Allocation Problem

Task Allocation Problem

You are given n tasks and k servers. Each task is described by a pair of integers \(s\) and \(e\), representing the start and end times respectively. A server can only handle one task at a time, meaning that two tasks can be allocated to the same server only if they do not overlap in time. Two tasks \(i\) and \(j\) are said to overlap if \(s_i < e_j\) and \(s_j < e_i\).

Your task is to determine whether it is possible to assign all tasks to the available servers such that no server handles overlapping tasks. The input begins with two integers \(n\) and \(k\), followed by \(n\) lines where each line contains the start and end times of a task.

For example, consider 3 tasks and 2 servers, with tasks given as follows:

1 3
2 5
4 6

It is possible to schedule these tasks (first task on first server and both the second and third on the second server with careful allocation) so that there is no overlap, and the answer would be YES.

inputFormat

The first line of input contains two integers (n) and (k), where (n) is the number of tasks and (k) is the number of servers. The next (n) lines each contain two integers (s) and (e), representing the start and end times of a task.

outputFormat

Output a single line containing YES if it is possible to assign all tasks to the available servers without overlapping tasks on any server; otherwise, output NO.## sample

3 2
1 3
2 5
4 6
YES