포럼
문제 ICPC00229

L. Limited Library

설명

During the summer break, fewer students are dwelling on campus, so this is the perfect time to add new books to the TU Delft library. These new books all have the same width, but they have varying heights. Because all existing bookcases are already full, the management board of the library has decided that they will add a new bookcase to display these new books.

The new bookcase has a number of shelves with varying heights. Each shelf in the bookcase can fit \(x\) books. Since there may be some leftover space, the management board would also like to display some art pieces in this bookcase, at most one per shelf. An art piece will only fit on a shelf if there are at most \(y\) books next to it, because the art pieces take up the same amount of space as \(x-y\) books. As an example, Figure shows a bookcase where three of the shelves have enough space for an art piece.

The management board wants you to find the largest number of shelves on which you can place an art piece, whilst also being able to fit all the new books on the shelves.

제약
입력 형식

The input consists of:
- One line with four integers \(n\), \(m\), \(x\), and \(y\) ($1 \leq n, m \leq
10^5\(, \)1 \leq y < x \leq 1000$), the number of shelves, the number of books, the number of books that fit on a full shelf, and the number of books that fit on a shelf next to an art piece.
- One line with \(n\) integers \(a\) (\(1 \leq a \leq 10^9\)), the heights of the shelves.
- One line with \(m\) integers \(b\) (\(1 \leq b \leq 10^9\)), the heights of the books.

출력 형식

If it is possible to fit all the \(m\) books into the \(n\) shelves, output the largest number of art pieces you can place. Otherwise, output "impossible".

예제 1
입력
4 8 4 2
4 8 6 2
1 2 3 5 7 7 8 8
출력
3
예제 2
입력
4 11 3 2
2 2 2 2
1 1 1 1 1 1 1 1 1 1 1
출력
1
예제 3
입력
2 10 3 2
8 6
4 2 1 3 6 2 1 3 4 5
출력
impossible
예제 4
입력
3 8 8 3
7 9 4
2 3 4 5 6 7 8 9
출력
3
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2024

평가 및 의견

L. Limited Library

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

L. Limited Library

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8