아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Backup

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

요약
요일별 백업 레벨 일곱 개와 복구 날짜가 주어질 때, 데이터를 복원하는 데 필요한 백업 파일의 요일을 순서대로 나열한다.
난이도

보통10점 중 4점

유형
구현, 시뮬레이션
정답자
아직 제출이 없습니다

문제

There are many different backup strategies. The easiest to understand are the differential and incremental backups.

With incremental backup, we create a copy of the data which were changed from the moment of the last backup: for instance, after a full backup on Sunday, on Monday we copy the data that were changed during Monday; the same goes for Tuesday, etc. With such strategy, the volume of data copied is relatively small, but it may require a lot of files to restore the data. For instance, to restore data on Friday, we would need backup copies from Sunday (full backup), Monday, Tuesday, Wednesday and Thursday.

With differential backup, we regularly create a full copy --- for instance, every Sunday. Next, on each day of the week we make a copy of all data modified after the last full backup: a Monday copy on Monday, a Monday and Tuesday copy on Tuesday, etc. The total volume of the backed up data is relatively large, but you only need two files to restore data: the last differential and the last full backup.

Dump(1), a popular backup freeware, operates with the concept of backup level, which can perform incremental or differential backup as well as more complex strategies, which cannot be reduced to the two former methods. The idea of backup levels as such is pretty simple: when we make an NN level backup, we copy all files modified from the moment of the last backup with the level lower than NN.  If there are no preceding lower-level backups, we make a complete backup copy of all data.

Write a program to figure out which backup files should be used for recovery based on the backup schedule.

입력

The first line of the input file contains the number MM -- the total number of tests in the file (0<M≤100,0000 < M \le 100\\,000).

Each following line of the input file consists of eight space-separated integers. The first seven numbers are schedule of backups, i.e. the levels of backup N_iN\_i, which are performed on the corresponding days of the week ii: on Sunday, Monday, Tuesday, etc. (0≤N_i≤90 \le N\_i \le 9). It is guaranteed that the zero-level backup is performed on Sunday, i.e. the first number is zero.

The eighth number is the day dd when data must be recovered (0≤d≤60 \le d \le 6). Note that 00 is Sunday and 66 is Saturday.

출력

For each line of the output file, print a sequence of numbers d_jd\_j corresponding to the days when the backup copies necessary for recovery were made (0≤d_j≤60 \le d\_j \le 6). Note that the earliest copy is always recovered first, followed by a later copy, hence the following must hold true: d_j<d_j+1d\_j < d\_{j+1} and N_d_j<N_d_j+1N\_{d\_j} < N\_{d\_{j+1}}. Moreover, the recovery always ends with the latest copy, so the last number in the line must equal dd.

예제1

  1. 예제 1

    입력
    4
    0 0 0 0 0 0 0 4
    0 8 8 8 8 8 8 3
    0 2 3 4 5 6 7 4
    0 7 2 6 3 5 4 4
    
    예상 출력
    4
    0 3
    0 1 2 3 4
    0 2 4