#K59867. Task Scheduling Within Time Slots

    ID: 30960 Type: Default 1000ms 256MiB

Task Scheduling Within Time Slots

Task Scheduling Within Time Slots

You are given a sequence of tasks and you need to determine if they can be scheduled into k time slots such that the total duration of tasks in each slot does not exceed a given time limit T.

More formally, suppose you have n tasks with durations d1, d2, \(\dots\), dn provided in order. You need to partition the tasks into at most k contiguous groups such that for each group the sum of durations satisfies:

\(\sum d_i \le T\)

If such a partition exists, print YES; otherwise, print NO.

Note: Each task must be scheduled in the given order without rearrangement.

inputFormat

The input is read from standard input and consists of four lines:

  1. A single integer k representing the number of available time slots.
  2. An integer n representing the number of tasks.
  3. n space-separated integers denoting the durations of the tasks.
  4. A single integer T representing the maximum allowed time per slot.

outputFormat

Output a single line to standard output containing the string YES if it is possible to schedule the tasks within k slots under the given time limitation. Otherwise, output NO.

## sample
3
3
4 2 3
5
YES