#C1531. Invoice Management System

    ID: 44747 Type: Default 1000ms 256MiB

Invoice Management System

Invoice Management System

You are given records for several departments. For each department, you're given its name and its remaining budget. Then, you are given a list of invoices for that department. Each invoice has an amount and a status (either paid or unpaid). Your task is to, for each department, determine:

  • The number of unpaid invoices.
  • The total amount due for the unpaid invoices.
  • Whether the remaining budget can cover the total unpaid amount. In other words, check if $$\text{budget} \geq \sum_{i=1}^{n}{\text{amount}_i}\,,$$ where the sum is taken only over the unpaid invoices.

Output the result for each department in the same order as input. For each department, print its name, the number of unpaid invoices, the total unpaid amount, and then YES if the budget is sufficient or NO otherwise.

inputFormat

The input is read from stdin and has the following format:

D
Department_1 Budget_1
N_1
Amount_11 Status_11
Amount_12 Status_12
... 
Amount_1N1 Status_1N1
Department_2 Budget_2
N_2
Amount_21 Status_21
... 
Department_D Budget_D
N_D
Amount_D1 Status_D1
... 
Amount_DND Status_DND

Where:

  • D is the number of departments.
  • For each department, the first line contains the department name and its budget.
  • The next line contains an integer N representing the number of invoices.
  • The following N lines each contain an invoice amount followed by its status, which is either paid or unpaid.

outputFormat

For each department, output 4 lines:

  • The department name.
  • The number of unpaid invoices.
  • The total amount of the unpaid invoices.
  • YES if the budget is at least the total unpaid amount, otherwise NO.

The output should be written to stdout.

## sample
3
HR 10000
2
2000 paid
3000 unpaid
IT 5000
3
1000 unpaid
2000 unpaid
1500 paid
Marketing 12000
1
5000 unpaid
HR

1 3000 YES IT 2 3000 YES Marketing 1 5000 YES

</p>