Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: poni
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.223 second
Submitted On: 2026-10-19 15:38:54
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pii pair<int, int>
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vi hero(n);
vector<pii> monster(m);
for (auto &x : hero) cin >> x;
for (auto &[pow, val] : monster) cin >> pow >> val;
sort(monster.begin(), monster.end());
int sum = 0;
vi ans(m, 0), npow(m, 0);
for (int i = 0; i < m; i++) {
auto [pow, val] = monster[i];
sum += val;
ans[i] = sum;
npow[i] = pow;
}
for (auto cur : hero) {
auto it = upper_bound(npow.begin(), npow.end(), cur);
if (it == npow.begin()) {
cout << "0\n";
continue;
}
--it;
int idx = it - npow.begin();
cout << ans[idx] << '\n';
}
}