Submission
Status:
[PPPPxSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Seng
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.181 second
Submitted On: 2026-11-04 22:04:40
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
const int N1=2e5+5, N2=8e5+5;
int h[N1];
int ans[N1];
int32_t main(){
ios::sync_with_stdio(0);cin.tie(0);
int n, m;cin >> n >> m;
priority_queue<pii, vector<pii>, greater<pii>> pq;
set<int> s;
for(int i = 1; i <= n; i++){
cin >> h[i];
s.insert(h[i]);
}
for(int i = 1; i <= m; i++){
int a, b;cin >> a >> b;
pq.push({a, b});
}
int sum = 0;
for(auto e : s){
while(!pq.empty() && pq.top().first <= e){
sum += pq.top().second;
pq.pop();
}
ans[e] = sum;
}
for(int i=1;i<=n;i++){
cout << ans[h[i]] << '\n';
}
}
/*
4 5
1 4 2 6
1 2
1 3
5 4
2 5
3 6
*/