Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Krovmoroz
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.209 second
Submitted On: 2026-10-24 22:04:29
#include <bits/stdc++.h>
using namespace std;
// struct custom_hash {
// size_t operator()(uint64_t x) const {
// static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
// x ^= FIXED_RANDOM;
// return x ^ (x >> 16);
// }
// };
struct my_pair {
int f;
int s;
bool operator<(const my_pair& other)const {
if (f == other.f) return s < other.s;
return f < other.f;
}
};
int n,m;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
vector<int> hero(n);
vector<my_pair> mon(m);
for (int i = 0; i < n; i++) cin >> hero[i];
for (int i = 0; i < m; i++) cin >> mon[i].f >> mon[i].s;
sort(mon.begin(),mon.end());
vector<long long> presum(m);
presum[0] = mon[0].s;
for (int i = 1; i < m; i++) presum[i] = mon[i].s + presum[i-1];
for (int i = 0; i < n; i++) {
my_pair ub; ub.f = hero[i]; ub.s = INT_MAX;
auto it = upper_bound(mon.begin(),mon.end(),ub);
if (it != mon.begin()) {
it--;
cout << presum[distance(mon.begin(),it)] << "\n";
}
else cout << 0 << "\n";
}
}