Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Few500

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

Language: cpp

Time: 0.212 second

Submitted On: 2026-03-21 16:41:53

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
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, long long>> monst(m);

    for (int i = 0; i < n; i++)
        cin >> heros[i];

    for (int i = 0; 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++)
    {
        int u = upper_bound(monst.begin(), monst.end(), make_pair(heros[i], LLONG_MAX)) - monst.begin();
        cout << (u == 0 ? 0 : monst[u - 1].second) << '\n';
    }

    return 0;
}