Submission
Status:
[-SSSSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: goine
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-11 10:14:48
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main() {
int hero_count, monster_count;
cin >> hero_count >> monster_count;
vector<int> heroes(hero_count);
for (int &h : heroes) cin >> h;
vector<pair<int,int>> monsters(monster_count);
for (auto &m : monsters) cin >> m.first >> m.second;
sort(monsters.begin(), monsters.end());
vector<long long> pref(monster_count);
pref[0] = monsters[0].second;
for (int i = 1; i < monster_count; i++)
pref[i] = pref[i-1] + monsters[i].second;
for (int h : heroes) {
int pos = upper_bound(monsters.begin(), monsters.end(),
make_pair(h, INT_MAX)) - monsters.begin() - 1;
if (pos >= 0) cout << pref[pos] << " ";
else cout << 0 << " ";
}
}