Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: robgornpeunpadpairoundnigumaipadnea

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

Language: cpp

Time: 0.289 second

Submitted On: 2025-12-07 21:42:07

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,m;cin>>n>>m;
    vector<ll> hero(n);for(auto &i:hero)cin>>i;
    vector<pair<ll,ll>> en(m);
    for(int i=0;i<m;i++){
        ll a,b;cin>>a>>b;
        en[i].first = a;en[i].second=b;
    }
    sort(en.begin(),en.end());
    vector<ll> qwe(m);
    qwe[0] = en[0].second;
    for(int i=1;i<m;i++){
        qwe[i] = en[i].second + qwe[i-1];
    }
    for(auto h:hero){
        auto idx = upper_bound(en.begin(),en.end(),make_pair(h,LLONG_MAX)) - en.begin()-1;
        if(idx < 0)cout<<0<<'\n';
        else cout<<qwe[idx] << '\n';
    }
}