Submission

Status:
[PPPPPPPPPPPPPPPPPPPP]

Score: 100

User: Dormon

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

Language: cpp

Time: 0.220 second

Submitted On: 2025-03-27 11:08:44

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
#define fr first
#define se second

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

    int n, m;
    cin >> n >> m;
    
    vector<ll> ans(n, 0);
    vector<pair<ll, ll>> hero(n), mon(m);

    for (int i = 0;i < n;i++){
        cin >> hero[i].fr;
        hero[i].se = i;
    }

    for (auto &[hp, c]:mon)
        cin >> hp >> c;
    
    sort(hero.begin(), hero.end());
    sort(mon.begin(), mon.end());

    // for (int i = 0;i < n;i++)
    //     cout << hero[i].se << ' ' << hero[i].fr << '\n';
    // cout << string(10, '-') << '\n';
    // for (int i = 0;i < m;i++){
    //     cout << mon[i].fr << ' ' << mon[i].se << '\n';
    // }
    // cout << string(10, '-') << '\n';
    int idx = 0;
    ll coin = 0ll;
    for (int i = 0;i < n;i++){
        while (idx < m && hero[i].fr >= mon[idx].fr){
            coin += mon[idx].se;
            idx++;
        }
        ans[hero[i].se] = coin;
    }
    for (int i = 0;i < n;i++)
        cout << ans[i] << '\n';
}