#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, s;
cin >> n >> s;
vector<long long> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
if (s == 0) {
sort(A.rbegin(), A.rend());
for (auto x : A) cout << x << ' ';
cout << '\n';
return 0;
}
if (s <= 100) {
for (int i = 0; i < s; i++) {
long long m, c;
cin >> m >> c;
sort(A.rbegin(), A.rend());
for (int j = 0; j < c; j++) {
A[j] -= m;
}
}
sort(A.rbegin(), A.rend());
for (auto x : A) cout << x << ' ';
cout << '\n';
return 0;
}
vector<long long> C(s), M(s);
bool eden = true;
for (int i = 0; i < s; i++) {
cin >> M[i] >> C[i];
if (C[i] != 1) eden = false;
}
if (eden) {
priority_queue<long long> pq;
for (auto x : A) pq.push(x);
for (int i = 0; i < s; i++) {
long long x = pq.top(); pq.pop();
x -= M[i];
pq.push(x);
}
vector<long long> res;
while (!pq.empty()) {
res.push_back(pq.top());
pq.pop();
}
for (auto x : res) cout << x << ' ';
cout << '\n';
return 0;
}
map<long long, long long> freq;
for (auto x : A) freq[x]++;
for (int i = 0; i < s; i++) {
long long m = M[i];
long long c = C[i];
map<long long, long long> newFreq;
while (c > 0) {
auto it = prev(freq.end());
long long val = it->first;
long long cnt = it->second;
freq.erase(it);
long long take = min(cnt, c);
long long stay = cnt - take;
if (stay > 0) newFreq[val] += stay;
newFreq[val - m] += take;
c -= take;
}
for (auto &p : freq) {
newFreq[p.first] += p.second;
}
freq.swap(newFreq);
}
vector<long long> res;
for (auto [val, cnt] : freq) {
for (int i = 0; i < cnt; i++) {
res.push_back(val);
}
}
sort(res.rbegin(), res.rend());
for (auto x : res) cout << x << ' ';
cout << '\n';
return 0;
}