Course Allocation in University

In a large university, various departments offer courses with different credit values. The university wants to assign courses to departments based on the department's capacity to handle the course credits. Each department has a specific capacity, and each course has a specific credit value. The goal is to assign one course to each department based on the following rules:

Input Format

Constraints

Output Format

A list of integers, where each integer represents the course ID assigned to the corresponding department, or -1 if no suitable course exists.

Examples

Input 1:

5
8 4 3 2 4
2
4 2

Output 1:

0 0 -1 1 0

Input 2:

4
2 3 5 7
3
5 3 3

Output 2:

-1 1 0 -1

Input 3:

4
10 21 30 41
2
2 1

Output 3:

0 1 0 1
Leetcode problem