CF241C.Mirror Box

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 10510^{5} cm long and 100100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights hlh_{l} and hrh_{r} centimeters above the floor. The picture below shows what the box looks like.

In the game, you will be given a laser gun to shoot once. The laser beam must enter from one hole and exit from the other one. Each mirror has a preset number viv_{i} , which shows the number of points players gain if their laser beam hits that mirror. Also — to make things even funnier — the beam must not hit any mirror more than once.

Given the information about the box, your task is to find the maximum score a player may gain. Please note that the reflection obeys the law "the angle of incidence equals the angle of reflection".

输入格式

The first line of the input contains three space-separated integers hl,hr,nh_{l},h_{r},n ( 0<h_{l},h_{r}<100 , 0<=n<=1000<=n<=100 ) — the heights of the holes and the number of the mirrors.

Next nn lines contain the descriptions of the mirrors. The ii -th line contains space-separated vi,ci,ai,biv_{i},c_{i},a_{i},b_{i} ; the integer viv_{i} ( 1<=vi<=10001<=v_{i}<=1000 ) is the score for the ii -th mirror; the character cic_{i} denotes ii -th mirror's position — the mirror is on the ceiling if cic_{i} equals "T" and on the floor if cic_{i} equals "F"; integers aia_{i} and bib_{i} ( 0<=a_{i}<b_{i}<=10^{5} ) represent the xx -coordinates of the beginning and the end of the mirror.

No two mirrors will share a common point. Consider that the xx coordinate increases in the direction from left to right, so the border with the hole at height hlh_{l} has the xx coordinate equal to 0 and the border with the hole at height hrh_{r} has the xx coordinate equal to 10510^{5} .

输出格式

The only line of output should contain a single integer — the maximum possible score a player could gain.

输入输出样例

  • 输入#1

    50 50 7
    10 F 1 80000
    20 T 1 80000
    30 T 81000 82000
    40 T 83000 84000
    50 T 85000 86000
    60 T 87000 88000
    70 F 81000 89000
    

    输出#1

    100
    
  • 输入#2

    80 72 9
    15 T 8210 15679
    10 F 11940 22399
    50 T 30600 44789
    50 F 32090 36579
    5 F 45520 48519
    120 F 49250 55229
    8 F 59700 80609
    35 T 61940 64939
    2 T 92540 97769
    

    输出#2

    120
    

说明/提示

The second sample is depicted above. The red beam gets 10+50+5+35+8+2=11010+50+5+35+8+2=110 points and the blue one gets 120120 .

The red beam on the picture given in the statement shows how the laser beam can go approximately, this is just illustration how the laser beam can gain score. So for the second sample there is no such beam that gain score 110.

首页