#K93587. Ticket Booking System Simulation
Ticket Booking System Simulation
Ticket Booking System Simulation
This problem simulates a ticket booking system. The system starts with a total of $T$ tickets available and processes $N$ customers in the order they arrive. Each customer has a name and a ticket value. The system sells tickets in the order of appearance until all tickets are sold. The total revenue is the sum of the ticket values for all sold tickets. Formally, if tickets are sold to customers $1, 2, \dots, k$, then the revenue is given by $\displaystyle \text{Revenue} = \sum_{i=1}^{k} v_i$, where $v_i$ is the ticket value of the $i$-th customer.
inputFormat
The input is read from standard input (stdin) and has the following format:
T N name1 value1 name2 value2 ... nameN valueN
Here, T
is the total number of tickets available, N
is the number of customers, and each of the next N
lines contains a customer's name (a string without spaces) and an integer representing the ticket value.
outputFormat
The output should be printed to standard output (stdout) and consists of two lines:
- The first line contains a single integer representing the total revenue from the sold tickets.
- The second line contains the names of the customers who bought a ticket in the order they purchased, separated by a single space. If no ticket was sold, print an empty line.
5
7
Alice 50
Bob 60
Charlie 70
David 80
Eve 90
Frank 100
Grace 60
350
Alice Bob Charlie David Eve
</p>