luogu#P5117. [USACO18DEC] The Bucket List B

[USACO18DEC] The Bucket List B

Problem Description

Farmer John is considering changing the way he assigns milk buckets when milking his cows. He believes this might let him use fewer buckets overall, but he does not know how many. Please help him.

Farmer John has NN cows (1N1001\le N\le 100), numbered 1N1\dots N for convenience. Cow ii needs to be milked from time sis_i to time tit_i, and during milking it requires bib_i buckets. Therefore, multiple cows may be milking at the same time; if so, they cannot share the same buckets. In other words, a bucket used for cow ii cannot be used by any other cow that is being milked during the time interval from sis_i to tit_i. Of course, that bucket can be used by other cows outside this time period. To simplify his work, FJ guarantees that at any moment, at most one cow starts or ends milking (that is, all sis_i and tit_i are pairwise distinct).

FJ has a storage room with buckets numbered 11, 22, 33, \dots in order. Under his milking strategy, when a cow (say, cow ii) starts milking (at time sis_i), FJ goes to the storage room and takes the smallest-numbered bib_i buckets to assign to cow ii for milking.

Compute how many buckets FJ needs to store so that he can successfully milk all cows.

Input Format

The first line contains NN. The next NN lines each describe one cow, containing three space-separated numbers sis_i, tit_i, and bib_i. Here sis_i and tit_i are integers between 110001\dots 1000, and bib_i is an integer between 1101\dots 10.

Output Format

Output one integer: the number of buckets FJ needs.

3
4 10 1
8 13 3
2 6 2
4

Hint

In this example, FJ needs 44 buckets. He uses buckets 11 and 22 to milk cow 33 (starting at time 22). He uses bucket 33 to milk cow 11 (starting at time 44). When cow 22 starts milking at time 88, buckets 11 and 22 can be reused, but bucket 33 cannot, so he will use buckets 11, 22, and 44.

Translated by ChatGPT 5