1、http://codeforces.com/contest/401/problem/B
2、题目:
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) andDiv2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held withoutDiv2) 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 theDiv1 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 exactlyk 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.
The first line contains two integers: x(1 ≤ x ≤ 4000) — the round Sereja is taking part in today, andk (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: "1num2 num1" (where num2 is the identifier of this Div2 round, num1 is the identifier of theDiv1 round). It is guaranteed that num1 - num2 = 1. If Sereja took part in a usualDiv2 round, then the corresponding line looks like: "2num" (where num is the identifier of thisDiv2 round). It is guaranteed that the identifiers of all given rounds are less thanx.
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
3 2 2 1 2 2
0 0
9 3 1 2 3 2 8 1 4 5
2 3
10 0
5 9
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 usualDiv2 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 usualDiv2 rounds.
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int b,e;
}c[4040];
bool cmp(node a,node bb){
return a.b<bb.b;
}
int main(){
int k,x,a,sumx,sumn,i;
scanf("%d%d",&x,&k);
for(i=0;i<k;i++)
{
scanf("%d",&a);
if(a-1)
{
scanf("%d",&c[i].b);
c[i].e=c[i].b;
}
else scanf("%d%d",&c[i].b,&c[i].e);
}
sort(c,c+k,cmp);
for(sumx=sumn=0,a=1,i=0;i<k;i++)
{
int tmp=c[i].b-a;
sumx+=tmp;
sumn+=tmp/2+((tmp%2)?1:0);
a=c[i].e+1;
}
sumx+=x-a;
sumn+=(x-a)/2+(((x-a)%2)?1:0);
printf("%d %d\n",sumn,sumx);
return 0;
}