This page is still under construction.

Parts of this page are still being built. What you see may change.

Scheduling

Time limit1sMemory limit256 MB

Summary
Decide whether n preemptible tasks with release times, deadlines, and processing times can be scheduled on m identical processors within their windows.
Level

Hard8 of 10

Topics
Greedy, Sorting, Intervals, Implementation
Solved
No attempts yet

Problem

Byteasar celebrates his thirteenth birthday. One of the gifts from his parents is a brand new computer. He hastily unwrapped his gift and started reading the computer's manual. It turned out that the computer has mm processors. Byteasar is very happy, because at last he is able to execute many tasks in parallel!

He swiftly prepared a list of nn tasks (numbered 11 through nn) that he plans to execute on his new computer. A processor can execute no more than a single task at once. Task ii takes c_ic\_i seconds to complete, and it is forbidden to start its execution less than p_ip\_i seconds since the gift's unwrapping or complete it later than k_ik\_i seconds after the gift's unwrapping. Every task's execution can be interrupted arbitrarily many times and it can be moved between different processors. However, it cannot be executed on two or more processors simultaneously. Moving a task between processors takes negligible time. Is it possible to schedule the execution of tasks so that each task is executed and completed within its timeframe? In other words, does there exist a strategy of starting, interrupting and moving tasks between processors that would allow Byteasar achieve his goal?

Input

The first line of the input contains two integers nn and mm (1≤n,m≤1001 \le n, m \le 100) denoting the number of tasks and the number of processors, respectively. The following nn lines describe Byteasar's tasks. The ii-th of them contains a description of task ii: three integers p_ip\_i, k_ik\_i and c_ic\_i (0≤p_i<k_i≤106;1≤c_i≤k_i−p_i0 \le p\_i < k\_i \le 10^6; 1 \le c\_i \le k\_i - p\_i) denoting the beginning and the end of the time interval when it is allowed to execute the ii-th task (expressed in seconds since the gift's unwrapping), and the time it takes to complete this task, respectively.

Output

If it is possible to complete all the tasks within their respective timeframes, print YES. Otherwise, print NO.

Examples2

  1. Example 1

    Input
    3 2
    3 8 3
    2 5 2
    3 7 3
    
    Expected output
    YES
    
  2. Example 2

    Input
    2 1
    0 1 1
    0 1 1
    
    Expected output
    NO