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

#BS0000161. Đom đóm vượt hang (Firefly)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đom đóm vượt hang (Firefly)

Firefly

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A firefly flies horizontally through a cave of length nn and integer height hh. The nn obstacles alternate: the first is a stalagmite rising from the floor, the second a stalactite descending from the ceiling, and so on. An obstacle of length dd from the floor blocks levels 11 through dd; one hanging from the ceiling blocks levels h−d+1h-d+1 through hh. The firefly chooses one integer level 1≤y≤h1\le y\le h and breaks every obstacle intersecting that level. Find the minimum number it must break and the number of levels attaining that minimum.

Input

  • The first line contains an even integer nn and an integer hh.
  • Each of the following nn lines contains the length did_i of obstacle ii; odd-indexed obstacles rise from the floor and even-indexed obstacles hang from the ceiling.

Output

Print two integers: the smallest number of obstacles hit and the number of integer levels attaining it.

Subtasks

  • Subtask 1 (20 points): 2≤n≤502\le n\le 50 and nn is even; 2≤h≤302\le h\le 30; 1≤di≤h1\le d_i\le h for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 2≤n≤50002\le n\le 5000 and nn is even; 2≤h≤50002\le h\le 5000; 1≤di≤h1\le d_i\le h for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le 2\cdot10^5 and nn is even; 2≤h≤5⋅1052\le h\le 5\cdot10^5; 1≤di≤h1\le d_i\le h for all 1≤i≤n1\le i\le n.

Examples

Input

6 5
1
3
4
2
2
4

Output

3 4

Explanation

For h=5h=5, the floor obstacles have lengths 1,4,21,4,2 and the ceiling obstacles 3,2,43,2,4. The numbers hit at levels 1,2,3,4,51,2,3,4,5 are respectively 3,3,3,4,33,3,3,4,3. Thus the minimum is 33 and four different levels attain it, so print 3 4.