Lasers | 프로그래밍의 벗 PivotOJ
PivotOJ

Lasers

시간 제한: 1000ms메모리 제한: 512MB출처: NOI 2019BOJ 19671
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Mr. Panda knows cats love laser toys, and decides to invest in a laser toy for Rar the Cat. The laser toy that Mr. Panda has bought consists of L evenly spaced lasers at the top of the toy, pointing downward. The 1st laser is located 0.5 units away from the leftmost edge and the Lth laser is located 0.5 units away from the rightmost edge of the toy. Every adjacent lasers are of distance 1 unit.

There are R rows of sliding walls, with each row containing a set of non-overlapping walls. Precisely, each row contains some number of walls whose total length is at most L. These walls can be slid to any position on the same row, as long as their relative positions along the row remain the same and they do not overlap. A wall of width x units (where x is a positive integer) will block exactly x consecutive lasers.

A possible toy with L = 11 and R = 3 is depicted in the diagram below:

[이미지 1]

Rar the Cat, being the curious cat as he is, wishes to know: Out of the L lasers in his toy, how many lasers will always be blocked by at least one wall in all possible configurations of the toy?

입력

Your program must read from standard input.

The first line of the input will contain two integers, L and R.

The next R lines of input will describe one row each. It will start with a single integer X, the number of sliding walls in the row. X integers will follow, indicating the widths of the X walls in that row, with the first integer indicating the width of the leftmost wall. Note that the sum of widths of the walls on each row cannot exceed L units.

출력

Your program should print to standard output.

Output a single integer on a single line, the number of lasers that will be blocked by at least one wall in all possible configurations of the toy.

예제

예제 1

입력
11 3
2 2 3
1 7
2 4 1
출력
3

예제 2

입력
10 3
3 1 5 1
4 2 2 3 1
3 1 6 2
출력
6

예제 3

입력
10 1
1 4
출력
0
코드를 제출하려면 로그인하세요.