#GD0000075. Chở xe qua sông II (Ferry Loading II)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chở xe qua sông II (Ferry Loading II)
Ferry Loading II
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
A ferry carries at most cars per crossing. Going across the river takes minutes and returning takes another minutes. There are cars arriving at the original terminal at nondecreasing times; only arrived cars may board. The ferry may depart whenever it chooses. Find the earliest time when all cars are delivered and the minimum number of outbound crossings achieving that time. No return is needed after the last delivery.
Input
The first line contains . The next lines contain car arrival times in nondecreasing order.
Output
Print two integers: the earliest time when all cars have crossed and the fewest outbound crossings needed to achieve it.
Subtasks
- Subtask 1 (20 points): ; ; for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for ).
- Subtask 2 (30 points): ; ; for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for ).
- Subtask 3 (50 points): ; ; for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for ).
Examples
Input
2 10 3
10
30
40
Output
50 2
Explanation
The ferry carries at most cars and crossing takes minutes. It takes the first car at minute and arrives at , returns at , then departs at with the other two cars, completing at minute in crossings.