CF18D.Seller Bob

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:128MB

AC君温馨提醒

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

题目描述

Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place:

  • A customer came to Bob and asked to sell him a 2_x_ MB memory stick. If Bob had such a stick, he sold it and got 2_x_ berllars.
  • Bob won some programming competition and got a 2_x_ MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it.

Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally.

去年,Bob 通过销售内存条赚取收入。在他的工作期间共持续了 nn 天,每天发生以下两种事件之一:

  • 一位顾客来到 Bob 处,要求购买一根容量为 2x2^x MB 的内存条。如果 Bob 当时恰好持有该容量的内存条,他就将其售出,并获得 2x2^x 贝尔拉(berllars)。
  • Bob 赢得了一场编程竞赛,并获得一根容量为 2x2^x MB 的内存条作为奖品。Bob 可以选择将这根内存条赠予某位朋友,或自己保留。

Bob 从不同时持有超过一根内存条,因为他担心混淆不同内存条的容量,从而无意中欺骗顾客。此外,已知对于每种容量的内存条,至多只有一位顾客希望购买该容量的内存条。现在,已知这 nn 天内所有顾客的购买需求以及 Bob 所赢得的所有编程竞赛奖品,Bob 想知道:若他采取最优策略,最多能赚取多少收入?

输入格式

The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2_x_ MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2_x_ MB memory stick (0 ≤ x ≤ 2000).

第一行输入包含一个整数 nn(1≤n≤50001 \leq n \leq 5000)—— 表示鲍勃的工作天数。接下来的 nn 行描述了这些工作日。
sell x 表示某一天有顾客来到鲍勃处购买一根容量为 2x2^x MB 的内存条(0≤x≤20000 \leq x \leq 2000)。
保证对于每个 xx,至多只有一行 sell x。
win x 表示某一天鲍勃赢得了一根容量为 2x2^x MB 的内存条(0≤x≤20000 \leq x \leq 2000)。

输出格式

Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time.

输出鲍勃在已知所有事件前提下所能获得的最大收益(单位:贝尔拉)。请注意,鲍勃一次最多只能持有一个内存条。

输入输出样例

  • 输入#1

    7
    win 10
    win 5
    win 3
    sell 5
    sell 3
    win 10
    sell 10

    输出#1

    1056
  • 输入#2

    3
    win 5
    sell 6
    sell 4

    输出#2

    0

输入解题思路,AI测评打分。不知道怎么写?

首页