#P9321. [EGOI 2022] Data Centers / 数据中心

[EGOI 2022] Data Centers / 数据中心

Background

Day 2 Problem A.

Translated from EGOI2022 datacenters.

CC BY-SA 3.0

Problem Description

Gonka Software (Gongsoft) is an Internet company that runs many services and has nn data centers around the world. Each data center has some available machines. For security and redundancy reasons, each service runs with one or more replicas at the same time. Each replica runs in a different data center and needs some machines to run. All replicas of one service require the same number of machines.

When Gongsoft plans to launch a new service ii that needs cic_i replicas, with each replica running on mm machines, it sorts the data centers in descending order by the number of currently available machines, and then uses mm machines in each of the first cic_i data centers.

Output the number of machines remaining in each data center after launching ss services.

Input Format

The first line contains two integers n,sn, s, representing the number of data centers and the number of services.

The second line contains nn integers aia_i, representing the initial number of available machines in each data center.

The next ss lines each contain two integers mi,cim_i, c_i, representing the required number of machines and the number of replicas.

Output Format

Output one line with nn integers in descending order, representing the number of machines remaining in each data center.

5 4
20 12 10 15 18
3 4
4 1
1 3
4 2
11 10 10 9 8

Hint

Sample explanation

Step Remaining machines Operation
Initial [20,12,10,15,18][20,12,10,15,18]
Before service 11 [20,18,15,12,10][20,18,15,12,10] Sort data centers in descending order
After service 11 [17,15,12,9,10][17,15,12,9,10] Use 33 machines in each of the first 44 data centers
Before service 22 [17,15,12,10,9][17,15,12,10,9] Sort data centers in descending order
After service 22 [13,15,12,10,9][13,15,12,10,9] Use 44 machines in the 11st data center
Before service 33 [15,13,12,10,9][15,13,12,10,9] Sort data centers in descending order
After service 33 [14,12,11,10,9][14,12,11,10,9] Use 11 machine in each of the first 33 data centers
Before service 44 Sort data centers in descending order
After service 44 [10,8,11,10,9][10,8,11,10,9] Use 44 machines in each of the first 22 data centers
End [11,10,10,9,8][11,10,10,9,8] Sort data centers in descending order

Constraints

For all testdata, 1n1051\le n\le 10^5, 0s5×1030\le s\le 5\times 10^3, 0ai1090\le a_i\le 10^9, 1mi1091\le m_i\le 10^9, 1cin1\le c_i\le n. It is guaranteed that at any time, the number of available machines in any data center is non-negative.

  • Subtask 1 (1212 points): n100n\le 100, s=0s=0.
  • Subtask 2 (1212 points): n100n\le 100, s10s\le 10.
  • Subtask 3 (99 points): n5×104n\le 5\times 10^4, s100s\le 100.
  • Subtask 4 (2626 points): ai103a_i\le 10^3.
  • Subtask 5 (1818 points): ci=1c_i=1.
  • Subtask 6 (2323 points): No additional constraints.

Translated by ChatGPT 5