#C7453. Conveyor Belt Simulation

    ID: 51326 Type: Default 1000ms 256MiB

Conveyor Belt Simulation

Conveyor Belt Simulation

You are given a conveyor belt with a capacity \( C \) and \( N \) packages that need to be delivered. Each package is described by three values: its size (a positive integer), a unique identifier, and a destination. In one time unit, you can load a number of packages onto the belt as long as the sum of their sizes does not exceed \( C \). Once loaded, these packages are immediately delivered.

The task is to compute the minimum number of time units needed to deliver all the packages. A common greedy strategy is to sort the packages in descending order of their sizes and then, in each time unit, iteratively select the largest package that fits in the remaining capacity of the belt.

Note: The input is read from stdin and the result should be printed to stdout.

inputFormat

The input is given via stdin and has the following format:

C N
size1 id1 destination1
size2 id2 destination2
... 
sizeN idN destinationN

where \( C \) is the capacity of the conveyor belt, \( N \) is the number of packages, and for each package, its size (an integer), its unique identifier (a string without spaces), and its destination (a string without spaces) are provided.

outputFormat

Output a single integer to stdout representing the minimum number of time units required to transport all packages.

## sample
10 3
5 A123 X
4 B234 Y
6 C345 Z
2