Balatro

시간 제한12초메모리 제한1024 MB

요약
각 부분 수열 길이마다 왼쪽에서 오른쪽으로 덧셈 카드와 곱셈 카드를 처리해 얻을 수 있는 최대 점수를 구하되, 곱셈 카드는 최대 k장만 쓴다.
난이도

어려움10점 중 8점

유형
동적 계획법, 그리디, 누적 합
정답자
아직 제출이 없습니다

문제

You’re given some cards arranged in a row. Each card has a value, and is one of two types: add, or multiply.

Compute the score for a row of cards as follows: Initially, the score is zero. Then, process the cards from left to right.

If it is an add card, increase the score by the card’s value. If it is a multiply card, multiply the score by the card’s value.

The final score is what you get after processing all the cards.

For all possible subsequence sizes, you’d like to know: what is the maximum possible score you can attain for a subsequence of that size (or fewer, if that size isn’t possible due to the limit on the number of multiply cards), maintaining their original order? Note, you can’t rearrange the cards after choosing them. Also, a subsequence doesn’t have to be contiguous.

입력

The first line of input contains two integers nn (2≤n≤2⋅1052≤n≤2 \cdot10^5) and kk (0≤k≤n0≤k≤n), where nn is the number of cards, and kk is the maximum number of multiply cards you can use.

Each of the next nn lines contains a letter ss (ss is either ‘a’ or ‘m’, always lower case) and an integer vv (2≤v≤1,0002≤v≤1\\,000), where ss indicates whether the card is an add card (‘a’) or a multiply card (‘m’), and vv is the value of the card.

It is guaranteed that the product of all multiply cards is at most 10910^9.

출력

Output nn lines. On each line, output the maximum score you can achieve for a subsequence of length at most 11, 22, 33, and so on, up to nn.

예제2

  1. 예제 1

    입력
    4 3
    a 3
    m 2
    a 8
    m 3
    
    예상 출력
    8
    24
    33
    42
    
  2. 예제 2

    입력
    6 1
    a 2
    m 5
    a 2
    a 2
    m 3
    a 3
    
    예상 출력
    3
    10
    13
    18
    21
    21