Source Code
#include <bits/stdc++.h>

using namespace std;
int n,m,y;
pair <int,int > a[100010];
int b[100001],c[100001];
map <int , pair <int ,int > > mp;
int main()
{
    cin >> n >> m;
    for (int i=0;i<n;i++) {
        cin >> y;
        a[i]={y,i+1};
    }
    for (int j=0;j<m;j++) {
        cin  >> b[j];
        c[j]=b[j];
    }
    sort(a,a+n);
    reverse (a,a+n);
    sort(b,b+m);
    int x = n-m;
    for (int i=0;i<m;i++) {
        mp[b[i]]=a[x+i];
    }
    for (int i=0;i<m;i++) {
        cout << mp[c[i]].second << ' ';
    }
}
Copy
Probability Game MOohamed_Mahfouz
GNU G++11
8 ms
664 KB
Wrong Answer