#K68732. Manage File Storage Operations
Manage File Storage Operations
Manage File Storage Operations
This problem simulates file management operations among multiple users. Each user has a storage limit, and files can be uploaded or transferred between users. There are two types of operations:
UPLOAD i x
: Upload a file of size \( x \) for user \( i \). This operation is successful only if it does not exceed the user's storage limit, i.e., if \( \text{current_storage}_i + x \leq \text{limit}_i \).TRANSFER i j x
: Transfer a file of size \( x \) from user \( i \) to user \( j \). This operation is successful only if user \( i \) has at least \( x \) size stored and the receiving user \( j \) can accommodate the file without exceeding their storage limit, i.e., if \( \text{current_storage}_i \geq x \) and \( \text{current_storage}_j + x \leq \text{limit}_j \).
At the end of all operations, you are required to print the total stored file size for each user.
inputFormat
The input is given from stdin in the following format:
- The first line contains two integers \( n \) and \( m \), where \( n \) is the number of users and \( m \) is the number of operations.
- The second line contains \( n \) integers representing the storage limits of the users.
- Each of the next \( m \) lines contains an operation, either
UPLOAD i x
orTRANSFER i j x
.
outputFormat
Print to stdout a single line containing \( n \) integers, where the \( i^{th} \) integer represents the total file size stored by user \( i \) after processing all operations. The integers should be separated by a single space.
## sample3 5
10 20 15
UPLOAD 1 5
UPLOAD 2 10
TRANSFER 1 3 2
TRANSFER 2 3 5
UPLOAD 3 7
3 5 14
</p>