B. Sereja and Contests

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.

Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.

Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.

Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.

Input

The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.

Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of the Div1round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.

Output

Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.

Sample test(s)
input
3 2
2 1
2 2
output
0 0
input
9 3
1 2 3
2 8
1 4 5
output
2 3
input
10 0
output
5 9
Note

In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with theDiv1 round.

The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.


解题说明:题目的意思翻译过来就是给出一个值作为上界,下面再给出n个值,判断从1到这个上界中未出现的数字有多少。不过题目做了一点变换,这些未出现的数字可以对应两种情况,一种情况是每行一个数字,一种是每行两个相差为1的数字,每一行对应一场比赛,问最多和最少的比赛次数。做法是先判断未出现的数字集合,然后从中找出能够连续出现的数字对数,这样就能得到最少的情况,最多的情况自然是未出现的数字个数。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include <algorithm>
#include<cstring>
using namespace std;

int main()
{
	int x, k, i, temp1, temp2, temp3, count = 0, count1 = 0, a[4000], j, k1, p, b[4000];
	memset(a, 0, sizeof(a));
	scanf("%d %d", &x, &k);
	for (i = 0; i<k; i++)
	{
		scanf("%d", &temp1);
		if (temp1 == 1)
		{
			scanf("%d %d", &temp2, &temp3);
			a[temp2] = 1;
			a[temp3] = -1;
		}
		else
		{
			scanf("%d", &temp2);
			a[temp2] = 1;
		}
	}
	k1 = 0;
	for (j = 1; j<x; j++)
	{
		if (a[j] == 0)
		{
			count++;
			b[k1] = j;
			k1++;
		}
	}
	p = 0;
	while (p<k1)
	{
		if (b[p + 1] - b[p] == 1)
		{
			count1++;
			p = p + 2;
		}
		else
		{
			p++;
		}
	}
	printf("%d %d\n", count - count1, count);
	return 0;
}


你可能感兴趣的:(B. Sereja and Contests)