Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: House123
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.789 second
Submitted On: 2026-03-12 01:15:26
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<int> hero(n);
vector<pair<int,int>> monster(m);
for(int i = 0; i < n ; i++) {
cin >> hero[i];
}
for(int i = 0; i < m ; i++ ){
cin >> monster[i].first >> monster[i].second;
}
sort(monster.begin(),monster.end());
vector<long long> prefix_sum(m+1);
prefix_sum[0] = monster[0].second;
for(int i = 1; i < m;i++){
prefix_sum[i] = prefix_sum[i-1] + monster[i].second;
}
for(int i = 0; i < n;i++){
auto it = upper_bound(monster.begin(),monster.end(),make_pair(hero[i],INT_MAX));
if(it == monster.begin()){
cout << 0 << endl;
} else {
it--;
cout << prefix_sum[it-monster.begin()] << endl;
}
}
}