#K59637. Maximize Cake Profit

    ID: 30909 Type: Default 1000ms 256MiB

Maximize Cake Profit

Maximize Cake Profit

You are given the task of baking various types of cakes to maximize profit. For each type of cake, you have a maximum production limit and a set of customers with specific demands for their favorite cake type. The goal is to determine the optimal number of cakes to bake for each type.

For each cake type (i), let (Q_i) represent the maximum number of cakes you can bake, and let (D_i) be the total demand coming from all customers who favor cake type (i). The optimal number of cakes to bake for type (i) is given by:

[ B_i = \min(Q_i, D_i), ]

where (B_i) is the number of cakes baked for type (i).

Note: Although each cake type also has a profit per unit value, it is not used in the computation for this problem.

inputFormat

The input begins with an integer (T) indicating the number of test cases. Each test case has the following format:

  1. An integer (C) representing the number of cake types.
  2. A line containing (C) space-separated integers: (Q_1, Q_2, \dots, Q_C), which indicate the maximum production quantity for each cake type.
  3. A line containing (C) space-separated integers: (P_1, P_2, \dots, P_C), representing the profit per unit for each cake type (this value is not used in the current calculation).
  4. An integer (N) representing the number of customers.
  5. (N) subsequent lines, each containing two space-separated integers (F_j) and (D_j) where (F_j) (1-indexed) is the customer's favorite cake type and (D_j) is the number of cakes the customer wishes to purchase.

outputFormat

For each test case, output a single line containing (C) space-separated integers. Each integer denotes the optimal number of cakes to bake for the corresponding cake type.## sample

1
2
100 50
10 20
3
1 30
2 10
1 20
50 10

</p>