Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: erng
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.531 second
Submitted On: 2026-03-05 22:00:23
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=2e5+5;
ll n, m, power[nx], x, y;
vector<pair<ll,ll>> mon;
int main()
{
// cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=0; i<n; i++)
{
cin>>power[i];
}
for (int i=0; i<m; i++)
{
cin>>x>>y;
mon.push_back({x, y});
}
vector<ll> pf(m), p(m);
sort(mon.begin(), mon.end());
for (int i=0; i<m; i++) p[i]=mon[i].first;
// cout<<"HI";
for (int i=0; i<m; i++)
{
if (i==0) pf[i]=mon[i].second;
else pf[i]=pf[i-1]+mon[i].second;
}
for (int i=0; i<n; i++)
{
ll idx=upper_bound(p.begin(), p.end(), power[i])-p.begin()-1;
if (idx<0) cout<<0<<'\n';
else cout<<pf[idx]<<'\n';
}
}