CF1413C.Perform Easily

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 66 strings and an infinite number of frets numbered from 11. Fretting the fret number jj on the ii-th string produces the note ai+ja_{i} + j.

Tayuya wants to play a melody of nn 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]a = [1, 1, 2, 2, 3, 3], and the sequence of notes is 4,11,11,12,12,13,134, 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 1010, the minimal one will be 33, and the answer is 10−3=710 - 3 = 7, as shown on the picture.

在与鹿丸交战后,多由也认为自己的笛子太过容易预测,于是将其换成了吉他。这把吉他有 66 根弦,以及从 11 开始编号的无限多个品丝(fret)。在第 ii 根弦上按住第 jj 品会发出音符 ai+ja_{i} + j。

多由也希望演奏一段包含 nn 个音符的旋律。每个音符都可以通过不同的“弦-品”组合来演奏。演奏的难易程度取决于所用所有品丝编号中最大值与最小值之差:该差值越小,演奏技巧就越容易完成。请确定该差值的最小可能值。

例如,若 a=[1,1,2,2,3,3]a = [1, 1, 2, 2, 3, 3],且待演奏的音符序列为 4,11,11,12,12,13,134, 11, 11, 12, 12, 13, 13(对应第二个样例),我们可以将第一个音符在第一根弦上演奏,其余所有音符均在第六根弦上演奏。此时所用的最大品号为 1010,最小品号为 33,答案即为 10−3=710 - 3 = 7,如图所示。

输入格式

The first line contains 66 space-separated numbers a1a_{1}, a2a_{2}, ..., a6a_{6} (1≤ai≤1091 \leq a_{i} \leq 10^{9}) which describe the Tayuya's strings.

The second line contains the only integer nn (1≤n≤100 0001 \leq n \leq 100\,000) standing for the number of notes in the melody.

The third line consists of nn integers b1b_{1}, b2b_{2}, ..., bnb_{n} (1≤bi≤1091 \leq b_{i} \leq 10^{9}), separated by space. They describe the notes to be played. It's guaranteed that bi>ajb_i \gt a_j for all 1≤i≤n1\leq i\leq n and 1≤j≤61\leq j\leq 6, in other words, you can play each note on any string.

第一行包含 66 个用空格分隔的整数 a1a_{1}、a2a_{2}、…、a6a_{6}(1≤ai≤1091 \leq a_{i} \leq 10^{9}),用于描述泰宇娅的六根琴弦。

第二行仅包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000),表示旋律中音符的个数。

第三行包含 nn 个用空格分隔的整数 b1b_{1}、b2b_{2}、…、bnb_{n}(1≤bi≤1091 \leq b_{i} \leq 10^{9}),用于描述待演奏的音符。题目保证对所有 1≤i≤n1\leq i\leq n 和 1≤j≤61\leq j\leq 6,均有 bi>ajb_i \gt a_j;换言之,每个音符均可在任意一根琴弦上演奏。

输出格式

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 100100-th fret is used each time, so the difference is 100−100=0100 - 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 1010, the minimal one will be 33, and the answer is 10−3=710 - 3 = 7.

在第一个样例测试中,最优策略是:第一个音符在第一根弦上演奏,第二个音符在第二根弦上演奏,第三个音符在第六根弦上演奏,第四个音符在第四根弦上演奏,第五个音符在第五根弦上演奏,第六个音符在第三根弦上演奏。此时每次均使用第 100100 品,因此差值为 100−100=0100 - 100 = 0。

在第二个测试中,一种最优策略是:第二个音符在第一根弦上演奏,其余所有音符均在第六根弦上演奏。此时最高品位为 1010,最低品位为 33,答案为 10−3=710 - 3 = 7。

输入解题思路,AI测评打分。不知道怎么写?

首页