Amplitude Hackathon '23 Practice Problem 4 - Gigatron Autoscaling

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 1G

Problem type

Gigatron needs to scale up and down. Given some requests to increase or decrease the number of pods, count the number of Gigatron pods running right now.

Gigatron is pegged to have a minimum of 1 running pod and a maximum of 1024 running pods. In the event a request would cause the number of pods to go outside of the limits, clamp it to either the minimum or maximum.

Constraints

1 \le N \le 10^5

1 \le P \le 1024

1 \le x \le 2 \cdot 10^3

Input Specification

The first line of input contains two integers N and P. There will be N requests and Gigatron starts with P running pods.

Each of the next N lines is of the form INC x or DEC x.

If the line is of the INC x, then the next request asks to increase the number of pods by x.

If the line is of the DEC x, then the next request asks to decrease the number of pods by x.

Output Specification

After each request, print the number of running pods.

Sample Input

3 100
DEC 50
DEC 50
INC 2000

Sample Output

50
1
1024

Sample Explanation

The first request drops the number of pods to 50. The second request would drop the number of pods to 0, but that is not allowed and there is 1 running pod. The third request would increase the number of pods to 2001, but that is not allowed and there are only 1024 running pods.


Comments

There are no comments at the moment.