Submission
Status:
[PP-SSSSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: Few500
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-21 16:23:09
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> heros(n);
vector<pair<int, int>> monst(m + 1);
for (int i = 0; i < n; i++)
cin >> heros[i];
for (int i = 1; i <= m; i++)
cin >> monst[i].first >> monst[i].second;
sort(monst.begin(), monst.end());
for (int i = 1; i <= m; i++)
monst[i].second += monst[i - 1].second;
for (int i = 0; i < n; i++)
{
auto it = upper_bound(monst.begin(), monst.end(), heros[i],
[](int hero, auto &monster)
{
return hero < monster.first;
});
if (it == monst.begin())
cout << 0 << '\n';
else
{
it--;
cout << it->second << '\n';
}
}
return 0;
}