Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Seng

Problemset: ฮีโร่และมอนสเตอร์

Language: cpp

Time: 0.398 second

Submitted On: 2026-11-08 10:16:53

// #include <bits/stdc++.h>
// using namespace std;
// #define int long long
// using pii = pair<int, int>;
// const int N=2e5+5;
// int h[N];
// const int Nt = 1e9+5;
// int t[Nt];
// void update(int idx, int val){
//     while(idx < Nt){
//         t[idx]+=val;
//         idx+=idx&-idx;
//     }
// }
// int query(int idx){
//     int sum = 0;
//     while(idx > 0){
//         sum+=t[idx];
//         idx-=idx&-idx;
//     }
//     return sum;
// }
// int32_t main(){
//     ios::sync_with_stdio(0);cin.tie(0);
//     int n, m;cin >> n >> m;
//     for(int i = 0; i < n; i++){
//         cin >> h[i];
//     }
//     for(int i = 0; i < m; i++){
//         int a, b;cin >> a >> b;
//         update(a, b);
//     }
//     for(int i=0;i<n;i++){
//         cout << query(h[i]) << '\n';
//     }
// }

// /* 
// 4 5
// 1 4 2 6
// 1 2
// 1 3
// 5 4
// 2 5
// 3 6
// */
#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];
unordered_map<int, int> ans;
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
*/