## Cat Girls

View as PDF

Points: 15 (partial)
Time limit: 1.4s
Memory limit: 256M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

This morning, you woke up and realized that some cats have turned into girls! In light of this exciting event, you have collected a large quantity of catnip to attract girls to your home (it's not as sketchy as it sounds). There, you plan to... take pictures of them while they are in a line. Don't worry, these are harmless pictures! However, your camera is quite small, and you may not be able to capture all of the cat-girls in a single photo. Your camera can only capture a contiguous subsequence of cat-girls in their line-up. Additionally, cat-girls keep showing up during the photo shoot! Even though this is a happy event, it troubles you because you always want to take the best picture you can with the available cat-girls. To complicate things further, some cat-girls want to nap so they leave the photo shoot. Fortunately, you have the cat-girls line up in a line in such a way that cat-girls only arrive and depart from the right end of the line.

Your camera's field of view is units wide. Each cat-girl has two attributes: and . represents the width of the pose the cat-girl is making, in the same units as the field of view of your camera. represents the cuteness of the cat-girl.

The cuteness of a picture is the sum of cuteness values of the cat-girls whose full poses are captured in the picture. To satisfy your desires, you write a program to calculate the maximum cuteness you can capture in a photo after each cat-girl arrives. Initially, there are no cat-girls in the line (but don't worry, we assure you that at least one will come!).

#### Input Specification

The first line of input will have , the number of events, and , your camera's field of view, separated by a single space. The next lines will be in one of the following forms:

• A cat-girl arrives at the right side of the line with pose width and cuteness . You should output the maximum cuteness of the best picture you can take at this point in time.

• Sadly, a cat-girl departs from the right side of the line. Don't worry, she'll surely visit again soon! You can be sure that the line will not be empty when this event happens.

At least 25% of the test cases will have .

#### Output Specification

After each cat-girl's arrival, output the maximum cuteness you can take a photo of.

#### Sample Input 1

8 5
A 3 10
A 4 15
D
A 2 9
A 1 10
A 4 15
D
A 6 1000

#### Sample Output 1

10
15
19
19
25
19

#### Sample Input 2

5 100
A 100 10000
A 14 28
A 88 166
A 75 39
A 1 1000

#### Sample Output 2

10000
10000
10000
10000
10000

#### Explanation for Sample Output 2

The first cat girl is simply too cute for the others to compete with! Now you have 5 photos of her.

• commented on Aug. 4, 2019, 2:08 p.m.

Who took away my Olympiads Role?

• commented on May 23, 2017, 11:21 a.m.

I need more pictures to understand the problem. Thanks!

• commented on May 23, 2017, 6:49 p.m.
• commented on May 24, 2017, 11:13 a.m.

yay, now i'm motivated to do this problem

• commented on May 24, 2017, 11:13 a.m.

Alas, I may have these 15 points.

• commented on Oct. 28, 2014, 4:04 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Nov. 1, 2014, 12:18 a.m.

It clarifies why the cuteness value is 10000.

• commented on Nov. 20, 2014, 11:26 a.m.

Exactly. The pictures were very helpful in my attempts to understand the problem.

• commented on Oct. 28, 2014, 4:03 p.m.