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

#GD0000083. Các trạm xăng (Gas Stations)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Các trạm xăng (Gas Stations)

Gas Stations

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Along a road of length LL, there are GG gas stations. Station ii at xix_i serves the closed interval [xi−ri,xi+ri][x_i-r_i,x_i+r_i]. Close as many stations as possible while ensuring every point in [0,L][0,L] remains served by at least one open station. If full road coverage is impossible even with all stations open, print -1.

Input

The first line contains L,GL,G. Each of the next GG lines contains integers xi,rix_i,r_i.

Output

Print the maximum number of stations that can be closed, or -1 if covering the whole road is impossible.

Subtasks

  • Subtask 1 (20 points): 1≤L≤1081\le L\le10^8; 1≤G≤151\le G\le 15; 0≤xi≤L0\le x_i\le L; 1≤ri≤L1\le r_i\le L.
  • Subtask 2 (30 points): 1≤L≤1081\le L\le10^8; 1≤G≤15001\le G\le 1500; 0≤xi≤L0\le x_i\le L; 1≤ri≤L1\le r_i\le L.
  • Subtask 3 (50 points): 1≤L≤1081\le L\le10^8; 1≤G≤1041\le G\le10^4; 0≤xi≤L0\le x_i\le L; 1≤ri≤L1\le r_i\le L.

Examples

Input

40 5
5 5
11 8
20 10
30 10
40 10

Output

2

Explanation

The stations serve [0,10][0,10], [3,19][3,19], [10,30][10,30], [20,40][20,40], and [30,50][30,50]. Keep stations 11, 33, and 44 to cover the road using three. Two stations cannot cover both endpoints without a gap, so two of the five can be closed.