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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define md ((st + nd) >> 1)
#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))
const int N = 100005;
int a[N], b[N], ans[N];
pair <int, int> p[N];
set <pair <int, int> > st;

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		p[i] = {a[i], i};
	}
	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
		st.insert({b[i], i});
	}
	sort(p, p + n);
	for (int i = 0; i < n; i++) {
		if ((int)st.size() == 0) break;
		auto it = st.lower_bound({100 - p[i].fi, 0});
		if (it == st.end()) it--;
		ans[it->se] = p[i].se;
		st.erase(it);
	}
	for (int i = 0; i < m; i++) {
		printf("%d ", ans[i] + 1);
	}
	return 0;
}
Copy
Probability Game aboAdnan
GNU G++17
129 ms
8.0 MB
Accepted