Problem I
Item Selection
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
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?
Input
The first line of input has five integers
-
is the number of items. The items have item numbers from to . -
is the fixed number of items displayed per page. -
is the number of the page currently displayed. -
is the number of preselected items. -
is the number of items you want.
Each of the next
Each of the next
Output
Output a single integer, which is the minimum number of checkbox and button clicks required to select exactly the items you want.
Sample Input 1 | Sample Output 1 |
---|---|
11 4 1 5 5 1 4 9 10 11 1 3 6 7 8 |
7 |