Submission

Status:
[PPPPPPPPPPPPPPPPPPPP]

Score: 100

User: Pera

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

Language: cpp

Time: 0.308 second

Submitted On: 2025-03-26 16:02:15

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

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    int heroes, monsters;
    cin >> heroes >> monsters;
    
    vector<int> power(heroes);
    for (int i = 0; i < heroes; ++i) {
        cin >> power[i];
    }
    
    vector<pair<int, int>> hp(monsters);
    for (int i = 0; i < monsters; ++i) {
        cin >> hp[i].first >> hp[i].second;
    }

    sort(hp.begin(), hp.end());
    
    vector<long long> sum(monsters);
    sum[0] = hp[0].second;
    for (int i = 1; i < monsters; ++i) {
        sum[i] = sum[i-1] + hp[i].second;
    }

    for (int i = 0; i < heroes; ++i) {
        auto it = upper_bound(hp.begin(), hp.end(), make_pair(power[i], INT_MAX));
        int idx = it - hp.begin() - 1;
        
        if (idx < 0) {
            cout << 0 << '\n';
        } else {
            cout << sum[idx] << '\n';
        }
    }
}