time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. 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 and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day biinclusive.

Output

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

Examples
input
4
M 151 307
F 343 352
F 117 145
M 24 128
output
2
input
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 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 day 140.

代码:

 1 #include <cstdio>
2 #include <cmath>
3 #include <cstring>
4 #include <cstdlib>
5 #include <iostream>
6 #include <sstream>
7 #include <algorithm>
8 #include <string>
9 #include <queue>
10 #include <vector>
11 using namespace std;
12 const int maxn= 500;
13 const double eps= 1e-6;
14 const int inf = 0x3f3f3f3f;
15 typedef long long ll;
16 int n,m,k;
17 int d1[maxn],d2[maxn];
18 char a;
19 int s,e;
20 int main()
21 {
22 scanf("%d",&n);
23 memset(d1,0,sizeof(d1));
24 memset(d2,0,sizeof(d2));
25 for(int i=1;i<=n;i++)
26 {
27 cin>>a>>s>>e;
28 if(a=='M')
29 {
30 for(int i=s;i<=e;i++)
31 d1[i]++;
32 }
33 else if(a=='F')
34 {
35 for(int i=s;i<=e;i++)
36 d2[i]++;
37 }
38 }
39 int ans=0;
40 for(int i=1;i<=366;i++)
41 {
42 int x=min(d1[i],d2[i]);
43 ans=max(ans,x);
44 }
45 printf("%d\n",ans*2);
46 return 0;
47 }

Codeforces 629 B. Far Relative’s Problem的更多相关文章

  1. Codeforces 629 A. Far Relative’s Birthday Cake

      A. Far Relative’s Birthday Cake   time limit per test 1 second memory limit per test 256 megabytes ...

  2. Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力

    B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...

  3. codeforces 629BFar Relative’s Problem

    B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  4. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  5. Codeforces--629B--Far Relative’s Problem(模拟)

    Far Relative's Problem Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I ...

  6. Codeforces Round #343 (Div. 2)-629A. Far Relative’s Birthday Cake 629B. Far Relative’s Problem

    A. Far Relative's Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...

  7. Codeforces Round #343 (Div. 2) B. Far Relative’s Problem

    题意:n个人,在规定时间范围内,找到最多有多少对男女能一起出面. 思路:ans=max(2*min(一天中有多少个人能出面)) #include<iostream> #include< ...

  8. Codeforces 629 E. Famil Door and Roads

    题目链接:http://codeforces.com/problemset/problem/629/E 询问这个简单环的期望.考虑将这个环拆成两部分. 令${deep[x]>=deep[y]}$ ...

  9. Codeforces Beta Round #17 A - Noldbach problem 暴力

    A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...

随机推荐

  1. eeeeeeeeeee

    http://58.241.123.38/hot.cdn.baidupcs.com/file/91623e76f776475da9c3223cdac861f0?xcode=68983c005f6e3c ...

  2. luogu3224 [HNOI2012]永无乡

    线段树合并好写好调,隔壁老王的treap+启发式合并难写难调 #include <iostream> #include <cstdio> using namespace std ...

  3. 如何将int转换为datetime?

    $timestamp = 1210003200; $datetime = date('Y-m-d H:i:s', $timestamp); echo "该时间戳代表的时间:", $ ...

  4. Android TV 开发(4)

    本文来自网易云社区 作者:孙有军 最后我们再来看看好友界面,改界面本地是没有xml的,因此我们直接来看看代码: 这里将使用到数据bean,与数据源的代码也贴出来如下: public class Con ...

  5. Python框架之Django学习笔记(十一)

    话说上次说到数据库的基本访问,而数据库我们主要进行的操作就是CRUD,也即是做计算处理时的增加(Create).读取(Retrieve)(重新得到数据).更新(Update)和删除(Delete),俗 ...

  6. PHP 获取上一个页面的url

    php $_SERVER["HTTP_REFERER"]变量可以获取上一个或前一个页面的URL地址. 比如有一个a.php页面,这个页面上有一个链接指向b.php页面,如果我们在a ...

  7. Zookeeper ZooDefs.Ids

    OPEN_ACL_UNSAFE  : 完全开放的ACL,任何连接的客户端都可以操作该属性znode CREATOR_ALL_ACL : 只有创建者才有ACL权限 READ_ACL_UNSAFE:只能读 ...

  8. FastDFS的安装(复制自己用)

    FastDFS 安装及使用 FastDFS 安装及使用 2012-11-17 13:10:31|  分类: Linux|举报|字号 订阅     Google了一下,流行的开源分布式文件系统有很多,介 ...

  9. Unity 移动方式总结

    1. 简介 在Unity3D中,有多种方式可以改变物体的坐标,实现移动的目的,其本质是每帧修改物体的position. 2. 通过Transform组件移动物体 Transform 组件用于描述物体在 ...

  10. 快乐的Linux命令行

    ls - 列出目录内容 -a 列出所有文件 -d 指定目录信息 -F 为目录增加/标识 -h 增强可读性 -l 列模式显示 -r 反序显示 -S 按照大小排序 -t 按照修改时间排序 file - 确 ...