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

#define ll long long
using namespace std;

ll NN=1e6+10;

int main()
{
    int n,m; cin >> n >> m;
    int a[n];
    vector <pair<int , int >> levels;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        levels.push_back({a[i] , i});
    }
    sort(levels.begin() , levels.end());
    int b[m];
    vector<pair<int, int>> friends;
    for(int i=0;i<m;i++)
    {
        cin >> b[i];
        friends.push_back({b[i] , i});
    }
    sort(friends.begin() , friends.end());
    int ans[m];
    while(levels.size()>m)
    {
        levels.pop_back();
    }
    for( auto it: friends)
    {
        ans[it.second] = levels.back().second;
        levels.pop_back();
    }
    for(int i=0; i<m ;i++)
    {
        cout << ans[i] + 1 << " ";
    }

    return 0;
}
Copy
Probability Game Practice_Til_Red00
GNU G++17
92 ms
4.1 MB
Accepted