Section: 5, Score: 76, Time limit per test: 30 seconds, Memory limit per test: 512MB, Input: stdin, Output: stdout
Agoda’s objective is to provide the best price to customers, but it is not always easy. There are many factors that affect the price. For example, the price of a hotel room depends on the number of rooms available, the number of people who want to book the room, etc.
For each hotel room, Agoda has a price for each day of the year. Agoda offers discounts for long stays. It also offers "Agoda Cash" on specific days in the year to make customers happy and encourage them to book more.
Mr. Agoji who always books hotels through Agoda, is planning his next long holiday. Specifically, he wants to go to Agodaland that has
He cannot wait to book the hotel rooms. He knows that he can maximize Agoda Cash and minimize the cost of staying in Agodaland by optimally selecting which hotel room to book for each day. However, there is another challenge for him. He must travel from one hotel to other, but not all hotels are connected to each other
Specifically, there are
Mr. Agoji has a superpower, on day one he can magically go to any one hotel. After that he can only travel from one hotel to another using the roads.
Mr. Agoji wants to know the maximum Agoda Cash he can get and the minimum cost of staying in Agodaland. Can you help him? It should be noted that you should maximize Agoda Cash first and then minimize the cost of staying in Agodaland.
Warning: Please note that if you're using a slower programming language like Python, there's a possibility that the code might exceed the time limit and result in a timeout error on large input.
The first line contains three space separated integers number of hotels
The next
The next
The next line contains an integer
The next line contains an integer, the number of Agoda Cash
There are three types of testcases. Constraints on the number of hotels,
Small Input
Medium Input
Large Input
Constraints on other parameters
All
All pair of
Two space separated integers, the maximum Agoda Cash, and the minimum cost of staying in Agodaland.
3 3 3
10 25 5
20 30 1
2 2 2
1 2 10
2 3 5
1 3 6
1
2 2 50
3
1 1 7
1 2 10
2 2 10
17 35
There are several ways to maximize the amount of Agoda cash earned, but one optimal solution is to stay at hotel 1 for all three days, which would earn $17 in Agoda cash. However, the cost of this stay would be $40. After trying all possible combinations, it becomes clear that it's impossible to earn more than $17 in Agoda cash.
However, it is possible to minimize the overall cost of the trip while still earning the maximum amount of Agoda cash. For example, the traveler could stay at hotel 1 on the first day, then travel to hotel 2 on the second day and stay there for the next two days. This would cost $10 for staying at hotel 1 on day 1, $10 for traveling from hotel 1 to hotel 2 on day 2, $31 for staying at hotel 2 on days 2 and 3, and a discount of $16 (50% of $31 rounded up for staying at hotel 2 for at least two consecutive days) for a total of $35.
2 5 1
25 25 50 50 50
100 120 60 60 60
1 2 20
1
2 2 20
6
1 2 30
1 3 40
2 1 20
2 2 30
2 3 40
2 4 10
100 309