CF1413C.Perform Easily
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1 . Fretting the fret number j on the i -th string produces the note ai+j .
Tayuya wants to play a melody of n notes. Each note can be played on different string-fret combination. The easiness of performance depends on the difference between the maximal and the minimal indices of used frets. The less this difference is, the easier it is to perform the technique. Please determine the minimal possible difference.
For example, if a=[1,1,2,2,3,3] , and the sequence of notes is 4,11,11,12,12,13,13 (corresponding to the second example), we can play the first note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 10 , the minimal one will be 3 , and the answer is 10−3=7 , as shown on the picture.
输入格式
The first line contains 6 space-separated numbers a1 , a2 , ..., a6 ( 1≤ai≤109 ) which describe the Tayuya's strings.
The second line contains the only integer n ( 1≤n≤100000 ) standing for the number of notes in the melody.
The third line consists of n integers b1 , b2 , ..., bn ( 1≤bi≤109 ), separated by space. They describe the notes to be played. It's guaranteed that bi>aj for all 1≤i≤n and 1≤j≤6 , in other words, you can play each note on any string.
输出格式
Print the minimal possible difference of the maximal and the minimal indices of used frets.
输入输出样例
输入#1
1 4 100 10 30 5 6 101 104 105 110 130 200
输出#1
0
输入#2
1 1 2 2 3 3 7 13 4 11 12 11 13 12
输出#2
7
说明/提示
In the first sample test it is optimal to play the first note on the first string, the second note on the second string, the third note on the sixth string, the fourth note on the fourth string, the fifth note on the fifth string, and the sixth note on the third string. In this case the 100 -th fret is used each time, so the difference is 100−100=0 .
In the second test it's optimal, for example, to play the second note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 10 , the minimal one will be 3 , and the answer is 10−3=7 .