#P16217. [ECUSTPC 2025] 克隆之击

    ID: 18232 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>数学贪心2025高校校赛

[ECUSTPC 2025] 克隆之击

Problem Description

Maddy and Baddy decide to compete in a battle of wits.
Initially, Maddy and Baddy have a multiset SS of nn positive integers: $S = \{a_1, a_1 + d, a_1 + 2d, \dots, a_1 + (n-1)d\}$. They decide to play a game with the following rules:

  • Maddy moves first, and Maddy and Baddy take turns.
  • On each move, the current player must add one positive integer into SS.
  • The game ends after each player has made mm moves.
  • Maddy’s goal is to make the final kk-connectivity number of SS as large as possible, while Baddy’s goal is to make it as small as possible.

The kk-connectivity number is defined as follows:

  • First sort SS. For each pair of adjacent numbers, if their difference is greater than kk, increase the connectivity number by 1. The connectivity number starts at 1.
  • An equivalent definition is: build a graph where each element of SS is a vertex, and add an edge between two vertices if their difference is at most kk. The kk-connectivity number is the number of connected components.

Assume both Maddy and Baddy are perfectly smart and always choose the best strategy. Please compute the value of the kk-connectivity number when the game ends.

Input Format

The first line contains an integer TT (1T1001 \le T \le 100), the number of test cases.
For each test case, the only line contains five integers n,a1,d,mn, a_1, d, m and kk (1n,a1,m1001 \le n, a_1, m \le 100, 0d,k1000 \le d, k \le 100), representing the initial size of SS, the first term and common difference of the arithmetic progression, the number of rounds, and the parameter kk, respectively.

Output Format

For each test case, output one integer ansans in one line, meaning the kk-connectivity number of SS at the end of the game when both Maddy and Baddy play optimally.

4
3 2 3 2 2
4 3 2 5 1
4 1 1 5 2
9 7 8 3 0
3
6
6
12

Hint

Explanation for Sample 1

For the first sample, the initial $S = \{(2 + 0 \times 3), (2 + 1 \times 3), (2 + 2 \times 3)\} = \{2, 5, 8\}$. One possible sequence of moves is:

  • Maddy adds 13, S={2,5,8,13}S = \{2, 5, 8, 13\}.
  • Baddy adds 3, S={2,3,5,8,13}S = \{2, 3, 5, 8, 13\}.
  • Maddy adds 18, S={2,3,5,8,13,18}S = \{2, 3, 5, 8, 13, 18\}.
  • Baddy adds 7, S={2,3,5,7,8,13,18}S = \{2, 3, 5, 7, 8, 13, 18\}.

After sorting, the adjacent differences are D1=1D_1 = 1, D2=2D_2 = 2, D3=2D_3 = 2, D4=1D_4 = 1, D5=5D_5 = 5, D6=5D_6 = 5. There are 2 differences greater than k=2k = 2, so the kk-connectivity number is 3.

Translated by ChatGPT 5