#P1937. [USACO10MAR] Barn Allocation G
[USACO10MAR] Barn Allocation G
Description
Farmer John has recently opened a new barn and is now accepting stall-allocation requests from cows, since some stalls have better views.
The barn contains stalls (), labeled to for convenience. Stall can hold cows (). The -th cow wants to stroll in a contiguous range of stalls from to (). In other words, this cow wants access to every stall in the interval , and to satisfy this request you must reserve one unit of capacity in every stall of that interval for this cow.
Given stall-allocation requests (), determine the maximum number of cows whose requests can be satisfied (without building additional stalls).
Input Format
- The first line contains two space-separated integers: .
- Lines to : line contains a single integer .
- Lines to : line contains two integers .
Output Format
Output a single line with the maximum number of requests that can be satisfied.
5 4
1
3
2
1
3
1 3
2 5
2 3
4 5
3
Hint
Consider the following example:
畜栏号: 1 2 3 4 5
+---+---+---+---+---+
容纳空间: | 1 | 3 | 2 | 1 | 3 |
+---+---+---+---+---+
Cow 1 XXXXXXXXXXX (1, 3)
Cow 2 XXXXXXXXXXXXXXX (2, 5)
Cow 3 XXXXXXX (2, 3)
Cow 4 XXXXXXX (4, 5)
John clearly cannot satisfy all requests, since stalls and are over-requested.
After testing, we find that we can satisfy cows , so the answer for this testdata is .
Source: USACO 2010 March Gold
Translator: @chrome01
Translated by ChatGPT 5
京公网安备 11011102002149号