Far Relative’s Problem【 区间覆盖】

来源:互联网 发布:crm系统数据 编辑:程序博客网 时间:2024/05/25 08:13

S - Far Relative’s Problem

CodeForces - 629B 

Famil Door wants to celebrate his birthday with his friends from Far Far Away. He hasn friends and each of them can come to the party in a specific range of days of the year fromai tobi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.

Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.

Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends.

Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai andbi (1 ≤ ai ≤ bi ≤ 366), providing that thei-th friend can come to the party from dayai to daybi inclusive.

Output

Print the maximum number of people that may come to Famil Door's party.

Example
Input
4M 151 307F 343 352F 117 145M 24 128
Output
2
Input
6M 128 130F 128 131F 131 140F 131 141M 131 200M 140 200
 
Output
4
Note

In the first sample, friends 3 and 4 can come on any day in range [117, 128].

In the second sample, friends with indices 3, 4, 5 and 6 can come on day140.

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

代码 

#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<queue>#include<stack>#include<vector>#define inf 0x3f3f3f#define mod 100000#define M  400using namespace std;struct data{int xx,yy;  } ; data a[M];int main(){ int n;while(~scanf("%d",&n)){for(int i=0;i<M;i++)a[i].xx=a[i].yy=0; for(int i=0;i<n;i++){char k;int x,y;int kk;getchar(); scanf("%c%d%d",&k,&x,&y);if(k=='M') kk=1;else kk=0;for(int j=x;j<=y;j++){if(kk) a[j].yy++;else a[j].xx++;}}int sum=0;for(int i=0;i<M;i++){if(a[i].xx&&a[i].yy){int ll=min(a[i].xx,a[i].yy);if(ll*2>sum) sum=ll*2;}}printf("%d\n",sum); } return 0; }


0 0
原创粉丝点击