Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: sulinx

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

Language: cpp

Time: 0.219 second

Submitted On: 2026-03-09 13:12:32

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m;
    cin >> n >> m;
    
    vector<ll> hero(n);
    for(int i = 0;i<n;i++){
        cin >> hero[i];
    }

    vector<pair<ll,ll>> monster(m);
    for(int i = 0;i<m;i++){
        cin >> monster[i].first >> monster[i].second;
    }sort(monster.begin(),monster.end());

    vector<ll> prefix(m+1,0);
    for(int j = 0;j<m;j++){
        prefix[j+1] = prefix[j] + monster[j].second;
    }

    for(int i = 0;i<n;i++){
        int pos = upper_bound(monster.begin(),monster.end(),make_pair(hero[i],LLONG_MAX)) - monster.begin();
        cout << prefix[pos] << '\n';
    }
}