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

#FT0000094. Đánh chặn tên lửa (Missile Interception)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đánh chặn tên lửa (Missile Interception)

Missile Interception

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

A country has one missile interception system protecting it against an enemy attack. The system detects nn incoming missiles in their arrival order, numbered from 11 to nn. Each missile has an integer height and an integer speed, both positive.

The first intercepted missile may have any height or speed. After intercepting a missile, the system can choose a missile arriving later only if both of the following conditions hold:

  • The next missile's height is not greater than the height of the previously intercepted missile.
  • The next missile's speed is not greater than the speed of the previously intercepted missile.

Equivalently, for selected indices i1<i2<⋯<iki_1<i_2<\cdots<i_k, a valid plan satisfies hij≥hij+1h_{i_j}\ge h_{i_{j+1}} and vij≥vij+1v_{i_j}\ge v_{i_{j+1}} for every 1≤j<k1\le j<k. Equality is permitted. Each missile may be intercepted at most once.

The system first maximizes the number of intercepted missiles. Different optimal plans may exist. Two plans are different whenever their selected sets of missile indices differ. If more than one optimal plan exists, the system chooses one of them uniformly at random.

Determine the maximum number of missiles the system can intercept and the probability that each missile belongs to the randomly chosen optimal plan.

Input

  • The first line contains the integer nn, the number of incoming missiles.
  • Each of the following nn lines contains two integers hih_i and viv_i, the height and speed of missile ii, respectively. These lines follow the order in which the missiles arrive.

Output

  • The first line must contain one integer: the largest possible number of intercepted missiles.
  • The second line must contain exactly nn real numbers in the order of missiles 1,2,…,n1,2,\ldots,n. The ii-th number is the probability that missile ii is included when an optimal plan is chosen uniformly at random.

Each probability must be in [0,1][0,1]. The absolute error of each probability must not exceed 10−410^{-4}. Printing, for example, 1212 digits after the decimal point is sufficient.

Original scoring rule: 40% of each test case's score is for the integer on the first line; the other 60% is for all nn probabilities on the second line. These two components are scored independently.

Subtasks

  • Subtask 1 (20 points): 1≤n≤181\le n\le18; 1≤hi≤1091\le h_i\le10^9 and 1≤vi≤1091\le v_i\le10^9 for every 1≤i≤n1\le i\le n. The number of optimal interception plans is finite and representable by C++ double.
  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 1≤hi≤1091\le h_i\le10^9 and 1≤vi≤1091\le v_i\le10^9 for every 1≤i≤n1\le i\le n. The number of optimal interception plans is finite and representable by C++ double.
  • Subtask 3 (50 points): 1≤n≤5⋅1041\le n\le5\cdot10^4; 1≤hi≤1091\le h_i\le10^9 and 1≤vi≤1091\le v_i\le10^9 for every 1≤i≤n1\le i\le n. The number of optimal interception plans is finite and representable by C++ double.

Examples

Example 1

Input

4
3 30
4 40
6 60
3 30

Output

2
0.33333 0.33333 0.33333 1.00000

Explanation

The four missiles have (hi,vi)(h_i,v_i) equal to (3,30)(3,30), (4,40)(4,40), (6,60)(6,60), and (3,30)(3,30), respectively.

No two missiles among the first three may be intercepted consecutively in arrival order because their heights and speeds increase. However, each of these missiles can precede missile 44, whose height and speed are not greater.

Thus, the three optimal plans are (1,4)(1,4), (2,4)(2,4) and (3,4)(3,4). Every such plan intercepts exactly 22 missiles, and no longer plan exists. Each of missiles 11, 22, and 33 belongs to exactly one of the three plans, so its probability is 1/3≈0.333331/3\approx0.33333. Missile 44 belongs to all three and therefore has probability 3/3=13/3=1.

Example 2

Input

4
5 5
4 4
5 4
3 3

Output

3
1.00000 0.50000 0.50000 1.00000

Explanation

Missile 11 has height 55 and speed 55 and can precede either missile 22 with (4,4)(4,4) or missile 33 with (5,4)(5,4). Missiles 22 and 33 cannot be intercepted consecutively in that order because the height would increase from 44 to 55.

Exactly two longest plans exist: (1,2,4)(1,2,4) and (1,3,4)(1,3,4), each of length 33. Missiles 11 and 44 appear in both plans and have probability 11. Missile 22 appears only in the first, and missile 33 only in the second, so each has probability 1/2=0.51/2=0.5.