Submission
Status:
[PPPPPPPPPPPPPPPPPPPP]
Score: 100
User: muekwakungaroo
Problemset: ฮีโร่และมอนสเตอร์
Language: cpp
Time: 0.230 second
Submitted On: 2025-03-31 10:30:05
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
ll ar[n];
for(int i=0;i<n;i++){
cin>>ar[i];
}
pair<int,int> pa[m];
for(int i=0;i<m;i++){
cin>>pa[i].first>>pa[i].second;
}
sort(pa,pa+m);
int idx[m+1];
ll pre[m+1];
pre[0]=0;
idx[0]=0;
for(int i=1;i<=m;i++){
// cout<<pa[i].first<<' '<<pa[i].second<<'\n';
idx[i]=pa[i-1].first;
}
pre[0]=0;
pre[1]=pa[0].second;
for(int i=2;i<=m;i++){
pre[i]=pre[i-1]+pa[i-1].second;
}
for(int i=0;i<n;i++){
cout<<pre[(upper_bound(idx,idx+m+1,ar[i])-idx)-1]<<'\n';
}
return 0;
}
/*
4 5
1 4 2 6
1 2
1 3
5 4
2 5
3 6
8 3
1 2 3 4 5 6 7 8
100 2
200 3
400 3
*/