Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Nay-O

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

Language: cpp

Time: 0.704 second

Submitted On: 2026-01-31 10:50:38

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

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int n, m; cin >> n >> m;
	map<int, long long> mp;
	vector<int> arr(n);
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	
	for(int i = 0; i < m; i++){
		int p, c; cin >> p >> c;
		mp[p]+=c;
	}
	
	vector<long long> v1 = {0}, v2 = {0};
	
	for(auto value : mp){
		v1.push_back(value.first);
		v2.push_back(value.second+v2.back());
	}
	
	v1.push_back(LLONG_MAX); v2.push_back(0);
	
	for(auto value : arr){
		int idx = upper_bound(v1.begin(), v1.end(), value)-v1.begin()-1;
		cout << v2[idx] << "\n";
	}
	
	return 0;
}