codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1089G.md (2290B)


      1 Source: https://codeforces.com/problemset/problem/1089/G
      2 
      3 G. Guest Student
      4 
      5 time limit per test
      6 
      7 1.5 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country.
     22 
     23 Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of seven integers $a_1, a_2, \dots, a_7$ ($a_i = 0$ or $a_i = 1$):
     24 
     25 * $a_1=1$ if and only if there are classes for guest students on Sundays;
     26 * $a_2=1$ if and only if there are classes for guest students on Mondays;
     27 * ...
     28 * $a_7=1$ if and only if there are classes for guest students on Saturdays.
     29 
     30 The classes for guest students are held in at least one day of a week.
     31 
     32 You want to visit the capital of Berland and spend the minimum number of days in it to study $k$ days as a guest student in Berland State University. Write a program to find the length of the shortest continuous period of days to stay in the capital to study exactly $k$ days as a guest student.
     33 
     34 Input
     35 
     36 The first line of the input contains integer $t$ ($1 \le t \le 10\,000$) — the number of test cases to process. For each test case independently solve the problem and print the answer.
     37 
     38 Each test case consists of two lines. The first of them contains integer $k$ ($1 \le k \le 10^8$) — the required number of days to study as a guest student. The second line contains exactly seven integers $a_1, a_2, \dots, a_7$ ($a_i = 0$ or $a_i = 1$) where $a_i=1$ if and only if classes for guest students are held on the $i$-th day of a week.
     39 
     40 Output
     41 
     42 Print $t$ lines, the $i$-th line should contain the answer for the $i$-th test case — the length of the shortest continuous period of days you need to stay to study exactly $k$ days as a guest student.
     43 
     44 Example
     45 
     46 Input
     47 
     48 ```
     49 3
     50 2
     51 0 1 0 0 0 0 0
     52 100000000
     53 1 0 0 0 1 0 1
     54 1
     55 1 0 0 0 0 0 0
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 8
     62 233333332
     63 1
     64 ```
     65 
     66 Note
     67 
     68 In the first test case you must arrive to the capital of Berland on Monday, have classes on this day, spend a week until next Monday and have classes on the next Monday. In total you need to spend $8$ days in the capital of Berland.