Submission

Status:

[PPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Krovmoroz

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

Language: cpp

Time: 0.223 second

Submitted On: 2026-01-16 23:04:57

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

int N,M;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> M;
    vector<int> hero(N);
    for (auto &x : hero) cin >> x;
    vector<pair<int,int>> mons(M);
    for (auto &x : mons) cin >> x.first >> x.second;
    sort(mons.begin(),mons.end());

    vector<long long> pref(M+1, 0);
    for (int i = 0; i < M; i++) pref[i+1] = pref[i] + mons[i].second;

    for (auto &x : hero) {
      auto it = upper_bound(mons.begin(),mons.end(),make_pair(x,INT_MAX));
      int idx = distance(mons.begin(),it);

      cout << pref[idx] << '\n';
    }
    return 0;
}