您的位置:首页 > 其它

CodeForces 401B Sereja and Contests

2015-11-06 16:52 453 查看
Sereja and ContestsCrawling in process...

Crawling failed
Time Limit:1000MS
Memory Limit:262144KB
64bit IO Format:
%I64d & %I64u

Description

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
num2num1" (where
num2 is the identifier of this
Div2 round, num1 is the identifier of the
Div1 round). 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 Input

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


Sample Output

Hint

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 the Div1 round.

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

代码:

#include <iostream>
#include <string.h>
using namespace std;

int main()
{
int n,k;
int op,d1,d2;
int num[4010];
while(cin>>n>>k)
{
memset(num,0,sizeof(num));
for(int i=1; i<=k; i++)
{
cin>>op;
if(op==1)
{
cin>>d2>>d1;
num[d2]=1;
num[d1]=1;
}
else
{
cin>>d2;
num[d2]=1;
}
}
int cnt=0;
int cnt1=0;
for(int i=1; i<=n-1;)
{
if(!num[i]&&!num[i+1]&&i+1<=n-1)
{
cnt++;
if(i==n-1) cnt1++;
else
cnt1+=2;
i=i+2;
}
else if(!num[i])
{
cnt1++;
i++;
}
else i++;
}
cout<<cnt1-cnt<<" "<<cnt1<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: