#K49932. Server Management

    ID: 28752 Type: Default 1000ms 256MiB

Server Management

Server Management

In this problem, you are given a set of servers, each with a maximum capacity. You need to simulate a sequence of operations on these servers. There are two types of operations:

  1. PING u v: Add a load of v to server u if the resulting load does not exceed the maximum capacity p. Formally, if the current load (S_u) satisfies (S_u + v \le p), then update (S_u \leftarrow S_u + v). If the server ID u is invalid (i.e. not in the range ([1, s])), simply ignore the operation.

  2. CHECK u: Output the current load on server u. If the server is invalid, output -1.

The input provides three integers (s), (p), and (q) representing the number of servers, the maximum capacity per server, and the number of operations respectively. Then, there are (q) lines each containing one operation.

Your task is to process all operations and print the results of the CHECK operations in the order they appear. Each result should be printed on a new line.

inputFormat

The first line contains three integers (s), (p), and (q) where (s) (1 ≤ s ≤ 10^5) is the number of servers, (p) (1 ≤ p ≤ 10^9) is the maximum capacity for each server, and (q) (1 ≤ q ≤ 10^5) is the number of operations. Each of the following (q) lines contains an operation in one of the following formats:

  • PING u v
  • CHECK u

Here, u and v are integers. For the PING operation, the load can only be added if it does not exceed the server's capacity. For the CHECK operation, output the current load of the specified server or -1 if it does not exist.

outputFormat

For each CHECK operation, output the current load on the specified server on a new line. If the server does not exist, output -1.## sample

3 100 5
PING 1 30
PING 1 70
PING 2 50
CHECK 1
CHECK 2
100

50

</p>