Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: FakeAnutin

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

Language: cpp

Time: 0.230 second

Submitted On: 2026-11-20 22:57:38

#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<long long> v;
	vector<pair<long long,long long>> ms;
	int mx=0;
	for(int i=1;i<=n;i++){
		int k; cin>>k; 
		v.push_back(k);
	}
	for(int i=1;i<=m;i++){
		int x,y; cin>>x>>y;
		ms.push_back({x,y});
	}
	sort(ms.begin(),ms.end());
	vector<long long> pf(m+1,0);
	for(int i=1;i<=m;i++){
		pf[i] = pf[i-1] + ms[i-1].second;
	}
	
	for(auto pw : v){
			int cnt = upper_bound(
	        ms.begin(), ms.end(),
	        make_pair(pw, LLONG_MAX)
	    ) - ms.begin();
	
	    cout << pf[cnt] << '\n';
	}
}