您的位置:首页 > 其它

Far Relative’s Problem【 区间覆盖】

2017-03-17 08:07 309 查看

S-FarRelative’sProblem

CodeForces-629B 

FamilDoorwantstocelebratehisbirthdaywithhisfriendsfromFarFarAway.Hehas
nfriendsandeachofthemcancometothepartyinaspecificrangeofdaysoftheyearfrom
aito
bi.Ofcourse,FamilDoorwantstohaveasmanyfriendscelebratingtogetherwithhimaspossible.

FarcarsareasweirdasFarFarAwaycitizens,sotheycanonlycarrytwopeopleofoppositegender,thatisexactlyonemaleandonefemale.However,Farissofarfromherethatnoothertransportationmaybeusedtogettotheparty.

FamilDoorshouldselectsomedayoftheyearandinvitesomeofhisfriends,suchthattheyallareavailableatthismomentandthenumberofmalefriendsinvitedisequaltothenumberoffemalefriendsinvited.Findthemaximumnumberoffriendsthat
maypresentattheparty.

Input

Thefirstlineoftheinputcontainsasingleintegern(1 ≤ n ≤ 5000) —thennumberofFamilDoor'sfriends.

Thenfollownlines,thatdescribethefriends.Eachlinestartswithacapitalletter'F'forfemalefriendsandwithacapitalletter'M'
formalefriends.Thenfollowtwointegersaiand
bi(1 ≤ ai ≤ bi ≤ 366),providingthatthe
i-thfriendcancometothepartyfromday
aitoday
biinclusive.

Output

PrintthemaximumnumberofpeoplethatmaycometoFamilDoor'sparty.

Example

Input
4
M151307
F343352
F117145
M24128


Output
2


Input
6
M128130
F128131
F131140
F131141
M131200
M140200


Output
4


Note

Inthefirstsample,friends3and
4cancomeonanydayinrange[117, 128].

Inthesecondsample,friendswithindices3,
4,5and6cancomeonday
140.

 思路区间覆盖的变形,对于每个元素用两个变量记录就可以

代码 

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<vector>
#defineinf0x3f3f3f
#definemod100000
#defineM400
usingnamespacestd;
structdata
{
intxx,yy;
};
dataa[M];
intmain()
{
intn;
while(~scanf("%d",&n))
{
for(inti=0;i<M;i++)
a[i].xx=a[i].yy=0;

for(inti=0;i<n;i++)
{
chark;
intx,y;intkk;
getchar();
scanf("%c%d%d",&k,&x,&y);
if(k=='M')kk=1;
elsekk=0;
for(intj=x;j<=y;j++)
{
if(kk)a[j].yy++;
elsea[j].xx++;
}
}
intsum=0;
for(inti=0;i<M;i++)
{

if(a[i].xx&&a[i].yy)
{
intll=min(a[i].xx,a[i].yy);
if(ll*2>sum)sum=ll*2;
}

}

printf("%d\n",sum);
}
return0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: