Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Score: 100
User: Nightingale
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.272 second
Submitted On: 2025-03-26 21:59:29
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a;
int b;
int wherehero = 0;
int indexx = 0;
cin >> a >> b;
vector<pair<int,int>> hero(a);
vector<pair<int,int>> monster(b);
vector<int> coin(b+1,0);
unordered_map<int,int> ans;
for(int i=0;i<a;i++){
cin >> hero[i].first;
hero[i].second = i;
}
sort(hero.begin(),hero.end(),greater<pair<int,int>>());
for(int i=0;i<b;i++){
cin >> monster[i].first >> monster[i].second;
}
sort(monster.begin(),monster.end(),greater<pair<int,int>>());
for(int i=b-1;i>=0;i--){
coin[i] = coin[i+1]+monster[i].second;
}
for(int i=0;i<b;i++){
if(hero[wherehero].first>=monster[i].first){
ans[hero[wherehero].second] = coin[i];
wherehero++;
i--;
}
}
for(int i=0;i<a;i++){
cout << ans[i] << '\n';
}
}