PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000075. Chở xe qua sông II (Ferry Loading II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn cars per crossing. Going across the river takes tt minutes and returning takes another tt minutes. There are mm 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 n,t,mn,t,m. The next mm 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): 1≤m≤241\le m\le 24; 1≤n,t,m≤14391\le n,t,m\le1439; 0≤a1≤a2≤⋯≤am0\le a_1\le a_2\le\cdots\le a_m for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for aia_i).
  • Subtask 2 (30 points): 1≤m≤2001\le m\le 200; 1≤n,t,m≤14391\le n,t,m\le1439; 0≤a1≤a2≤⋯≤am0\le a_1\le a_2\le\cdots\le a_m for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for aia_i).
  • Subtask 3 (50 points): 1≤m≤14391\le m\le 1439; 1≤n,t,m≤14391\le n,t,m\le1439; 0≤a1≤a2≤⋯≤am0\le a_1\le a_2\le\cdots\le a_m for integer, nondecreasing arrival times (the original statement gives no separate numeric maximum for aia_i).

Examples

Input

2 10 3
10
30
40

Output

50 2

Explanation

The ferry carries at most 22 cars and crossing takes 1010 minutes. It takes the first car at minute 1010 and arrives at 2020, returns at 3030, then departs at 4040 with the other two cars, completing at minute 5050 in 22 crossings.