Optimized Cheating

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

요약
한 슬롯의 값을 시작으로 덧셈, 뺄셈, 곱셈, 나눗셈 연산을 적용해 배열의 다른 곳에 없는 값으로 만들되 최소 연산 횟수와 순서를 구하는 문제이다.
난이도

어려움10점 중 8점

유형
BFS, 그래프, 최단 경로, 수학
정답자
아직 제출이 없습니다

문제

Bob’s favorite game just released a limited-time item for sale that will boost his game character’s power significantly. However, there is not enough time for Bob to acquire sufficient in-game currency to purchase the item. Bob thus decides to resort to a cheat tool he found online to modify his in-game currency value.

The cheat tool will take two values xx and yy specified by Bob and overwrites all memory slots that contain the value xx with the value yy. Bob does not want to use the cheat tool unsafely. He does not want to modify any memory slots other than the one that stores his currency value and cause the game to crash. Therefore, Bob needs to make sure that his currency value does not have any duplicate in the game’s memory space before running the cheat tool. Bob can use a set of operations provided by the game to modify his currency value, such as doing missions, purchasing items, and so on. Those operations can add, subtract, multiply or divide his currency value by a constant. All those operations will only change Bob’s currency value, and they will not affect any other memory slots. Bob cannot use an operation that would cause his currency value to become negative (e.g. buying an item that costs more than his available currency).

Bob knows that the memory space of the game can be represented as an array consisting of nn integers. He also knows the location of the memory slot within this array that stores his currency value. However, Bob does not know how to modify his currency value as quickly as possible in order to use the cheat tool safely. Can you help him?

입력

The first line of input contains three integers nn, mm, and kk (1≤n≤1041 ≤ n ≤ 10^4, 1≤m≤1,0001 ≤ m ≤ 1\\, 000, 1≤k≤n1 ≤ k ≤ n), where nn is the number of memory slots in the game’s memory space, mm is the number of operations that Bob can use, and kk is the 11-based index of the memory slot that stores Bob’s in-game currency value in the game’s memory space.

The next nn lines each contain a single integer between 11 and 10910^9, giving the values stored in the game’s memory space in order.

The next mm lines each contain a single character p (+, -, *, or /) and an integer vv (1≤v≤1091 ≤ v ≤ 10^9) that describe one operation that Bob can use to change his currency value. If Bob’s current currency value is uu, then after applying the operation his currency value will become uu p vv. For instance, applying an operation + 33 will increase Bob’s currency value by 33. Divisions are integer divisions (e.g., 7/3=27 / 3 = 2). An operation cannot be applied if it would result in a negative currency value. Each operation can be applied multiple times (including zero).

출력

If it is possible for Bob to make to his in-game currency value unique in the game’s memory space, output a single integer tt on the first line, the minimum number of operations that Bob must apply. Then output tt lines that each have an integer denoting the 11-based index of the operation that Bob should apply in order. If there are multiple ways to apply the operations, you may output any of them.

If it is impossible for Bob to make his currency value unique in the game’s memory space, output −1-1.

예제1

  1. 예제 1

    입력
    5 3 4
    2
    1
    3
    2
    3
    - 1
    * 2
    + 3
    
    예상 출력
    1
    2