Source Code
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N=2e5+5;

int n,m;
pair <int,int> arr [N];
int main (){
cin>>n>>m;
for (int i=1; i <=n;i++){
int a;cin>>a;
arr [i]={a,i};
}
vector <pair <int,int> >v;
for (int i=0;i <m;i++){
int a;cin>>a;v.push_back({a,i+1});
}
sort (arr+1,arr+n+1);
sort (v.rbegin (),v.rend ());
int ans [n+1];
int j=1;
for (int i=0;i <m;i++){
ans [v [i].second]=arr [j].second;
j++;
}
for (int i=1;i <=m;i++){
cout <<ans [i]<<' ';
}
}




Copy
Probability Game FEAR
GNU G++17
86 ms
3.4 MB
Accepted