| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 287 | 56 | 41 | 36.283% |
Hanbyeol and Eunha have finalized a real estate contract to create their secret hideout. They plan to shop for household appliances to make it both cozy for living and fun for spending time. They aim to fit exactly $N$ appliances into their limited hideout space.
They can choose from $K$ types of appliances at the appliance store, each with its own price. Hanbyeol and Eunha want to acquire $N$ appliances at the lowest possible cost.
However, they cannot simply choose any appliances. Hanbyeol prefers $A$ types of appliances, and Eunha prefers $B$ types. Their preferences may overlap. To reach a compromise, they have agreed that among the $N$ appliances, at least $M$ appliances must be from the types Hanbyeol prefers, and at least $M$ appliances must also be from the types Eunha prefers.
Please help Hanbyeol and Eunha decide which appliances to purchase under these conditions.
The first line contains two space-separated integers: $N,ドル denoting the count of appliances that fit in the hideout, and $K,ドル denoting the count of the types of appliances that the appliance store has. (1ドル \le N \le K \le 300,000円$)
The following line contains three space-separated integers: $M,ドル denoting the minimum count of bought appliances that must be from the types favored by each girl; $A,ドル denoting the number of types that Hanbyeol prefers; and $B,ドル denoting the number of types that Eunha prefers. (1ドル\le M \le A,B \le N$)
The following line contains $K$ space-separated integers: $c_1,c_2, \cdots c_K$, where $c_i$ denotes the cost of the $i$-th type of appliance that the store has. (1ドル \le c_i \le 10^9$)
The following line contains $A$ space-separated integers: $a_1,a_2,\cdots,a_A$, denoting the index of appliances that Hanbyeol prefers. (1ドル \le a_i \le K;$ $i \ne j \rightarrow a_i \ne a_j$)
The following line contains $B$ space-separated integers: $b_1,b_2,\cdots,b_B$, denoting the index of appliances that Eunha prefers. (1ドル \le b_i \le K;$ $i\ne j \rightarrow b_i \ne b_j$)
Output the minimum cost to fulfill all constraints. If it is impossible, output -1 instead.
Modified constraints apply: 1ドル \le N \le K \le 16$.
Modified constraints apply: 1ドル \le N \le K \le 300,000円;$ $\boldsymbol{\underline{M=A=B;}}$ $\boldsymbol{\underline{a=b,}},ドル i.e., what Eunha prefers is also preferred by Hanbyeol, and vice-versa.
Modified constraints apply: 1ドル \le N \le K \le 1,000円$.
Original constraints apply: 1ドル \le N \le K \le 300,000円$.
3 5 2 2 2 3 1 4 1 5 1 2 1 2
5
It is optimal to select the 1ドル$st, 2ドル$nd, and 4ドル$th appliance, with a total cost of 5ドル$.
3 5 1 2 3 3 1 4 1 5 3 5 1 2 4
6
It is optimal to select the 2ドル$nd, 3ドル$rd, and 4ドル$th appliance, with a total cost of 6ドル$.
University > 서강대학교 > CSE4152 문제해결프로그래밍실습 > 2024-2학기 기말고사 코딩 테스트 5번