Ice Cream Thief Jiho
Time limit1sMemory limit1024 MB
Jiho repeatedly eats the largest remaining ice cream (leftmost on ties), and eating one whose amount is divisible by 7 reverses the remaining row; report the original index of each eaten ice cream.
- Level
Medium7 of 10
- Topics
- Heap, Simulation, Implementation, Array
- Solved
- No attempts yet
Problem
Jiho visits the ice cream shop every day. While eating ice cream, Jiho could not help but be startled. He had accidentally eaten mint chocolate. Most people dislike mint chocolate because it tastes like toothpaste. One can only wonder who came up with the idea of brushing one's teeth with ice cream. Anyway, tired of buying ice cream every time, Jiho has decided to steal ice cream from now on.
At the ice cream shop, N ice creams of various flavors are arranged in a row. The ice creams are numbered: the leftmost is number 1, the next to its right is number 2, ..., and the rightmost is number N. Jiho always picks the ice cream with the largest amount and eats all of it. If several ice creams have the largest amount, he eats the leftmost one.
Like most people, Jiho dislikes mint chocolate flavor. Fortunately, Jiho can determine an ice cream's flavor from its amount. According to Jiho's rule, if the amount of an ice cream is a multiple of 7, it is mint chocolate flavor; otherwise, it is not mint chocolate flavor.
Keep in mind that Jiho hates mint chocolate. When Jiho eats a mint chocolate ice cream, he becomes furious and reverses the order of the remaining ice creams left to right. That is, if there are K ice creams, he swaps the i-th ice cream and the (K - i + 1)-th ice cream. (1 ≤ i ≤ ⌊K / 2⌋)
Jiho wants to eat M of the N ice creams. Given the amounts of the ice creams, write a program to find the numbers of the ice creams Jiho eats.
Input
The first line gives the total number of ice creams N and the number of ice creams Jiho will eat M.
The second line gives N integers A1, A2, ..., AN. Here Ai is the amount of ice cream i.
All input is separated by spaces.
Output
Over M lines, the i-th line (1 ≤ i ≤ M) prints the number of the ice cream Jiho eats i-th.
Constraints
- 1 ≤ N ≤ 100,000
- 1 ≤ M ≤ N
- 1 ≤ Ai ≤ 1,000,000,000
Hint
The amount of input and output is large, so using fast input and output is recommended.