Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Kikii

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

Language: cpp

Time: 0.226 second

Submitted On: 2026-03-12 16:52:03

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    vector<pair<int,int>> e(m);
    for(int i = 0; i < m; i++){
        cin >> e[i].first >> e[i].second;
    }
    sort(e.begin(), e.end());
    vector<long long> pref(m);
    long long idx = 0;
    for(int i = 0; i < m; i++){
        idx += e[i].second;
        pref[i] = idx;
    }
    for(int i = 0; i < n; i++){
        auto it = upper_bound(e.begin(), e.end(), make_pair(v[i], INT_MAX));
        int id = it - e.begin() - 1;
        if(id >= 0)
            cout << pref[id] << "\n";
        else
            cout << 0 << "\n";
    }
}