아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Gym

시간 제한10초메모리 제한256 MB

요약
각 예약을 원하는 기계에서 가능한 시간 구간 안의 한 시간에 배정하되, 어떤 기계든 사용 중인 시각의 총 개수를 최소로 만들고 불가능하면 NIE를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 시뮬레이션, 구간
정답자
아직 제출이 없습니다

문제

Byteasar is an owner of a newly opened gym. Because market competition is high, he decided to approach every aspect of his business professionally and offer an advanced booking system for his customers.

The gym is equipped with kk various fitness machines. When placing a reservation the customer declares his desire to use a certain gym device for one hour at his chosen time interval. The system then determines the exact times when customers will be using gym equipment, so that no device is assigned to two different reservations at the same time.

Byteasar already received all nn reservations for the near future. He noted rightly, that if at some point no person uses the gym, the lights and the air conditioning could be turned off, and the supplements outlet could be closed. As a part of the savings plan, he would like to arrange the exercise sessions in such a way that the total number of hours when the gym is used by at least one person is minimized. Help him with this task.

입력

The first line of the input contains two integers nn and kk (1≤n≤1,000,0001\leq n \leq 1\\,000\\,000, 1≤k≤1091\leq k \leq 10^9) denoting the number of reservation requests and the number of devices in the gym, respectively. The gym devices are numbered using integers 11 through kk; for simplicity also the hours are numbered using consecutive integers starting from 1.

The next nn lines describe the placed reservations: the ii-th of these lines contains three integers a_ia\_i, b_ib\_i and p_ip\_i (1≤a_i≤b_i≤1091\leq a\_i\leq b\_i\leq 10^9, 1≤p_i≤k1\leq p\_i\leq k) denoting that the ii-th customer expressed his desire to use the device p_ip\_i for one hour in a time interval ranging from hour a_ia\_i to hour b_ib\_i, inclusive.

출력

If it is possible to plan the exercise sessions, so that all reservations are met and no piece of equipment is used at the same time by two people, the output should contain n+1n+1 lines. The first line should contain the minimum number of hours when the gym is used by at least one person. The ii-th of the next nn lines should contain a single integer t_i∈\[a_i,b_i]t\_i\in \[a\_i,b\_i] indicating that within the ii-th reservation the device p_ip\_i is used during the hour t_it\_i.

If it is not possible to schedule the exercise in accordance with these requirements, you should output the word NIE (Polish for no).

예제2

  1. 예제 1

    입력
    4 2
    1 3 1
    1 1 1
    1 3 2
    3 3 2
    
    예상 출력
    2
    3
    1
    1
    3
    
  2. 예제 2

    입력
    3 1
    1 2 1
    1 2 1
    1 2 1
    
    예상 출력
    NIE