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 cows (), numbered for convenience. Cow needs to be milked from time to time , and during milking it requires 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 cannot be used by any other cow that is being milked during the time interval from to . 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 and are pairwise distinct).
FJ has a storage room with buckets numbered , , , in order. Under his milking strategy, when a cow (say, cow ) starts milking (at time ), FJ goes to the storage room and takes the smallest-numbered buckets to assign to cow for milking.
Compute how many buckets FJ needs to store so that he can successfully milk all cows.
Input Format
The first line contains . The next lines each describe one cow, containing three space-separated numbers , , and . Here and are integers between , and is an integer between .
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 buckets. He uses buckets and to milk cow (starting at time ). He uses bucket to milk cow (starting at time ). When cow starts milking at time , buckets and can be reused, but bucket cannot, so he will use buckets , , and .
Translated by ChatGPT 5