struct

 avatar
user_7940789
c_cpp
a month ago
806 B
11
Indexable
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)


struct MyStruct
{
	int first=0;
	int second = 0;
};

bool comp(MyStruct a, MyStruct b){
	return(a.first < a.first);
}

int main() {
	int t, n;

	cin >> t;
	while (t--) {
		cin >> n;
		vector<MyStruct> arr(n);
		vector<int> ans(1005, 0);

		REP(i, n) {
			cin >> arr[i].first;
		}

		REP(i, n) {
			cin >> arr[i].second;
		}

		sort(arr.begin(), arr.end(),comp);

		int greaterCount = 0;
		REP(i, n) {

			greaterCount = arr[i].second;
			REP(j, n) {

				if (greaterCount == 0 && ans[j] == 0) {
					ans[j] = arr[i].first;
					break;
				}

				if (ans[j] == 0)
					greaterCount--;
			}
		}

		REP(i, n) {
			cout << ans[i] << " ";
		}
		cout << endl;
	}
}
Leave a Comment