시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB115571.429%

문제

GoncaSoft is an internet company that runs many services and has n data centers worldwide. Each data center has a number of available machines. For security and redundancy reasons, one or more copies of each service are running at the same time. Each copy runs in a separate data center, and requires a number of machines to run on. All the copies of a given service require the same number of machines.

When GoncaSoft plans to launch a new service i that requires ci copies, each running on mi machines, it sorts the data centers in descending order by their current available machines, and then uses mi machines in each of the top ci data centers.

Please calculate the remaining available machines in the data centers after launching s services in a given order.

입력

The first line of the input contains two space-separated integers n and s, representing the number of data centers GoncaSoft has and the number of new services GoncaSoft wants to launch.

The next line contains n space-separated integers, representing the number of available machines in each of the n data centers, before any services are launched.

The next s lines describe the services that will be launched: the ith line contains two space-separated integers mi and ci, representing the number of machines and the number of copies the ith service requires.

출력

Output one line containing n space-separated integers sorted in descending order, representing the number of remaining available machines in the data centers after all services have launched.

제한

  • 1 ≤ n ≤ 100 000 and 0 ≤ s ≤ 5 000.
  • Each data center has at most 109 machines initially.
  • 1 ≤ mi ≤ 109 for each service i such that 1 ≤ i ≤ s.
  • 1 ≤ ci ≤ n, for each service i such that 1 ≤ i ≤ s.
  • The data centers will always have enough machines for the new services.

서브태스크

번호배점제한
112

n ≤ 100, s = 0.

212

n ≤ 100, s ≤ 10.

39

n ≤ 50 000, s ≤ 100.

426

Each data center has initially at most 1 000 machines.

518

ci = 1 for all services from 1 to s.

623

No further constraints.

예제 입력 1

5 4
20 12 10 15 18
3 4
4 1
1 3
4 2

예제 출력 1

11 10 10 9 8
Step Available Machines Operations
Beginning 20 12 10 15 18
Service #1: before launching 20 18 15 12 10 Sort the data centers in descending order.
Service #1: after launching 17 15 12 9 10 Use 3 machines in each of the top 4 data centers.
Service #2: before launching 17 15 12 10 9 Sort the data centers in descending order.
Service #2: after launching 13 15 12 10 9 Use 4 machines in the top data center.
Service #3: before launching 15 13 12 10 9 Sort the data centers in descending order.
Service #3: after launching 14 12 11 10 9 Use 1 machine in each of the top 3 data centers.
Service #4: before launching 14 12 11 10 9 Sort the data centers in descending order.
Service #4: after launching 10 8 11 10 9 Use 4 machines in each of the top 2 data centers.
End 11 10 10 9 8 Sort the data centers in descending order.

채점 및 기타 정보

  • 예제는 채점하지 않는다.