#C6078. Classroom Scheduling Problem

    ID: 49798 Type: Default 1000ms 256MiB

Classroom Scheduling Problem

Classroom Scheduling Problem

You are given \(n\) classrooms and \(m\) classes. Each class is defined by its start time and end time. Your task is to assign each class to one of the available classrooms such that no two classes in the same classroom overlap.

A classroom can be used for a class if its last scheduled class ends at or before the start time of the new class. In other words, if a classroom is available at time \(T\), it can accommodate a class starting at time \(s\) if \(T \le s\). If it is possible to assign all classes to classrooms without conflict, print YES followed by the classroom assignments for each class in the order of input (one assignment per line). Otherwise, print NO.

inputFormat

The first line contains two integers \(n\) and \(m\), the number of classrooms and the number of classes respectively.

Each of the next \(m\) lines contains two integers, representing the start time and end time of a class.

outputFormat

If a valid assignment exists, output YES on the first line. Then output \(m\) lines where the \(i\)th line (1-indexed) contains the assigned classroom number for the \(i\)th class (in the same order as input).

If no valid assignment exists, output NO only.

## sample
3 5
1 4
2 5
6 8
3 7
8 10
YES

1 2 1 3 1

</p>