Dry Ice Cream

시간 제한2초메모리 제한512 MB

요약
주어진 용량의 빈 병들로 시작해, 채우기, 버리기, 옮기기 동작만 사용하여 혼합 용기에 정확히 T리터를 남기는 동작 순서를 만든다.
난이도

보통10점 중 6점

유형
BFS, 그래프, 시뮬레이션, 수학
정답자
아직 제출이 없습니다

문제

Dino loves ice cream.  In case he ever run out of ice cream at his office, he keeps a stash of dry ice in order to quickly make new ice cream.

His recipe for making ice cream includes exactly TT liters of dry ice. Unfortunately, he has no marked containers in his office. Instead, he keeps a set of bottles of known total volume.

He wants to use this in order to transfer TT liters of dry ice from his dry ice container to the container in which he is mixing his ice cream. To do this, he should perform a sequence of three different kinds of actions. He may either fill a bottle with dry ice from the dry ice container until the bottle is full, empty the contents of a bottle into the ice container, or transfer dry ice from one bottle into other until either the first bottle becomes empty or the target bottle becomes full.

Can you help Dino construct a plan in order to transfer TT liters of dry ice into the ice cream mix?

입력

The first line of the input contains an integer 1≤N≤1001 \le N \le 100, the number of bottles.

The next line contains NN integers, separated by spaces. These are the volumes of all the bottles, in liters. Each volume is between 11 and 100100 liters.

The final line contains the integer 1≤T≤1001 \le T \le 100, the volume in liters of dry ice needed for the ice cream.

출력

If it is not possible to add the correct amount of dry ice, output impossible. Otherwise, output a sequence of moves that moves TT liters into the ice cream mix.

You may output the following moves:

  • fill x: Fill bottle xx from the ice cream container until it is full.
  • discard x: Empty bottle xx into the sink.
  • transfer x y: Pour from bottle xx into bottle yy until either yy is full or xx is empty.

When pouring dry ice into the ice cream mix, use y=0y = 0 as the target bottle.

You may output at most 100,000100\\,000 moves.

예제2

  1. 예제 1

    입력
    2
    7 8
    10
    
    예상 출력
    fill 2
    transfer 2 1
    transfer 2 0
    discard 1
    fill 2
    transfer 2 1
    transfer 2 0
    discard 1
    fill 2
    transfer 2 0
    
  2. 예제 2

    입력
    2
    2 4
    3
    
    예상 출력
    impossible