#BS0000453. Mua một chuyến, miễn phí các chuyến còn lại (Buy one, get the rest free)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mua một chuyến, miễn phí các chuyến còn lại (Buy one, get the rest free)
Buy one, get the rest free
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
GetsJo rents entire flights. Paying for a flight priced also makes all flights costing at most available at no additional charge. Each flight has an origin, destination, capacity, price and departure day. All contestants must reach city by the end of day .
Day 0 is today. A flight leaves city in the evening of day and arrives at city the following morning. Contestants can wait in any city, take a connecting flight on the evening of arrival, and follow different routes. Each flight carries at most its stated capacity. Contestants already in city may stay there. Find the minimum total rental cost under the promotion, or report that no feasible plan exists.
Input
The first line contains (cities, days, flights). Each of the next lines contains five integers : origin, destination, capacity, rental price and departure day. The last line contains integers , the initial contestant counts.
Output
Print Case #1: followed by the minimum integer cost, or Impossible if not all contestants can reach the destination. If no flight is needed, the cost is 0.
Subtasks
- Subtask 1 (20 points): , , , , , , , , ; no two flights share the same .
- Subtask 2 (30 points): , , , , , , , , ; no two flights share the same .
- Subtask 3 (50 points): , , , , , , , , ; no two flights share the same .
Examples
Input 1
5 4 5
1 5 100 30000 0
2 4 10 10000 0
2 4 10 10000 1
4 5 25 25000 2
2 5 100 40000 3
1 20 0 5 100
Output 1
Case #1: 30000
Explanation 1
The contestant in city 1 needs the flight costing 30000. Two groups of ten from city 2 reach city 4 on days 1 and 2; all 25 there fly to city 5 on day 2 and arrive on day 3. The 100 already at the destination stay. Cost 30000 is necessary and sufficient.
Input 2
2 1 1
1 2 99 10400 0
100 0
Output 2
Case #1: Impossible
Explanation 2
There are only 99 seats for 100 contestants who must travel from city 1 to city 2 in one day.