Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stdlib.h> 
#include <time.h>
#include <stack>
#include <map>
#include <math.h>
#include <cmath>
#include <string.h>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define pb push_back 
const int N = 3e5+5 , MX = 1e9+1 ;
const ll MXL=1e18 , MOD = 1e9 + 7 ; 
pair<int,int> a[N] , b[N] ;
int ans[N];
int main(){
//   freopen("input.txt", "r", stdin);
  int n ,m ;
  cin >> n >> m ;
  for(int i=0,x ; i<n ; i++){
    scanf("%d" , &x );
    a[i]={x,i};
  }
  for(int i=0,x ; i<m ; i++){
    scanf("%d" , &x );
    b[i]={x,i};
  }
  sort( a, a+n );
  sort( b, b+m );
  for(int i=0 ; i<m ; i++ ){
    // cout<<b[i].second << " " << a[m-1-i].second<<endl;
    ans[b[i].second]= a[m-1-i].second;
  }
  for(int i=0 ; i<m ; i++ )
    cout<<ans[i]+1 << " ";
  return 0 ; 
}
Copy
Probability Game Rand()
GNU G++17
53 ms
3.2 MB
Accepted