Item Selection

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

요약
미리 선택된 항목과 페이지 UI에서 토글, 전체 선택, 전체 해제, 페이지 이동을 사용해 원하는 항목만 선택하는 최소 클릭 수를 구한다.
난이도

보통10점 중 5점

유형
동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

You are browsing a website that lists items for sale. The website has a paging UI that displays a fixed number of items per page, one page at a time.

For example, if there are 5555 items and the page displays exactly 2020 at a time, then there are 33 pages in total. Items 11 through 2020 are on page 11, items 2121 through 4040 are on page 22, and items 4141 through 5555 are on page 33.

You may navigate and select items using these UI elements:

  • A checkbox for every item on the current page. After you click a checkbox, a selected item becomes unselected, and an unselected item becomes selected. You cannot click a checkbox for an item that is not on the current page.
  • A "Select All" button. All unselected items on the current page become selected after you click this button.
  • A "Deselect All" button. All selected items on the current page become unselected after you click this button.
  • A "Next Page" button. Clicking it navigates to the next page and increments the current page number by one. This button is disabled on the last page.
  • A "Previous Page" button. Clicking it navigates to the previous page and decrements the current page number by one. This button is disabled on the first page.

The website has pre-selected some items for you based on its machine learning recommendation algorithm. The recommendation may or may not work for you. You know exactly the items that you want to purchase, which may differ from the pre-selected items. What is the minimum number of checkbox and button clicks required to select exactly the items you actually want?

입력

The first line of input has five integers n,mn, m (1≤m≤n≤1031 \leq m \leq n \leq 10^3), ss (1≤s≤⌈nm⌉1 \leq s \leq \lceil \frac{n}{m} \rceil), p,qp, q (0≤p,q≤n0 \leq p, q \leq n), where:

  • nn is the number of items. The items have item numbers from 11 to nn.
  • mm is the fixed number of items displayed per page.
  • ss is the number of the page currently displayed.
  • pp is the number of preselected items.
  • qq is the number of items you want.

Each of the next pp lines contains an integer ii (1≤i≤n1 \le i \le n). These are the item numbers of the preselected items. These pp items are distinct and are listed in increasing order. It is possible that the website has pre-selected none of the items (p=0p = 0), in which case the input has no lines for pre-selected items.

Each of the next qq lines contains an integer jj (1≤j≤n1 \le j \le n). These are the item numbers of the items you want to buy. These qq items are distinct and are listed in increasing order. It is possible that you want to buy none of the items (q=0q = 0), in which case the input has no lines for items you want.

출력

Output a single integer, which is the minimum number of checkbox and button clicks required to select exactly the items you want.

예제1

  1. 예제 1

    입력
    11 4 1 5 5
    1
    4
    9
    10
    11
    1
    3
    6
    7
    8
    
    예상 출력
    7