Source Code
#include <bits/stdc++.h>
using namespace std;
 
#define S second
#define F first
#define LL long long 
#define LINF 100000000000000000
#define INF 1000000000
 
const int N = 1e6+10;
const LL MOD = 1e9+7;

vector<pair<int,int>>vec,vec1;
int ans[N];

int main()
{      
    //freopen("out.txt","w",stdout);

    int n,m;
    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        vec.push_back({x,i});
    }
    for(int i=1;i<=m;i++){
        int x;scanf("%d",&x);
        vec1.push_back({x,i});
    }

    sort(vec.begin(),vec.end());
    sort(vec1.begin(),vec1.end());
    reverse(vec1.begin(),vec1.end());

    for(int i=0;i<m;i++)
        ans[vec1[i].S] = vec[i].S;
    
    for(int i=1;i<=m;i++)
        printf("%d ",ans[i]);
    puts("");
}
Copy
Probability Game Hazem17
GNU G++17
69 ms
3.4 MB
Accepted