Inspiring Professors

시간 제한3초메모리 제한2048 MB

요약
각 강의에 정원이 충분한 강의실을 배정하되, 친근한 교수 순서대로 더 좋은 강의실을 주는 사전순 최적 배정을 구한다.
난이도

보통10점 중 6점

유형
그리디, 정렬, 구현
정답자
아직 제출이 없습니다

문제

At TU Delft, more and more courses are going back to on-campus lectures. So, naturally, it becomes more difficult to effectively schedule which lecturer can have which lecture hall. They asked you, an algorithm expert, for help on this sub-problem:

There are nn lectures that happen at the same time, numbered 11 to nn. In the iith course, x_ix\_i students will attend the lecture on-campus. The lectures are ordered by friendliness of the professor who gives the lecture, with the friendliest lecturer (we all know who that is) giving lecture 11.

There are mm lecture halls. The lecture halls are numbered from 11 to mm and the jjth lecture hall has capacity c_jc\_j. The list of mm lecture halls is ranked on "niceness", with the nicest lecture hall on top.

Write a program that reads in the lectures and lecture halls and makes a valid assignment of the halls to lectures. In a valid assignment, the capacity of the hall assigned to a lecture should be greater or equal than the number of students attending.

If there exist multiple valid assignments, compute the assignment which maximizes the niceness of the lecture hall of the friendliest professor. If there are still multiple assignments, maximize the niceness of the lecture hall of lecturer 2, and so on.

입력

The input consists of:

  • One line containing two integers nn (1≤n≤50001\leq n\leq 5000) and mm (1≤m≤50001\leq m \leq 5000), the number of lectures and halls, respectively.
  • The next line contains nn integers x_ix\_i, with x_ix\_i (1≤x_i≤1091\leq x\_i \leq 10^9) the number of students attending the iith lecture.
  • The last line contains mm integers c_jc\_j, with c_jc\_j (1≤c_j≤1091\leq c\_j \leq 10^9) the capacity of lecture hall jj.

출력

If there is a valid assignment, output a line with nn numbers, with the iith being equal to the number of the lecture hall that gets assigned to lecture ii.

If there is no valid assignment, output "impossible".

예제2

  1. 예제 1

    입력
    3 3
    4 5 6
    6 5 5
    
    예상 출력
    2 3 1
    
  2. 예제 2

    입력
    5 5
    3 2 1 4 8
    6 8 1 7 5
    
    예상 출력
    1 4 3 5 2