CF2208B.Cyclists

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Cyclists

Bob likes to play an interesting tower defense game on his mobile phone. In the game, he must play cards to defeat his opponents!

There are nn cards placed in a queue called a deck. At any moment, Bob is only able to play the cards that are currently placed in the first kk positions in the deck. In each turn, Bob selects a card placed in the first kk positions, removes it from the deck, plays it, and then places the same card back at the bottom of the deck. In other words, in each turn an element from the first kk elements in the queue is selected, moved to the end of the queue, and all elements placed after it are moved one index to the front.

One card is called the win-condition, and Bob wants to play it as many times as possible. However, each card also has a cost needed to play. The ii-th card (initially placed at the ii-th position) costs Bob aia_i energy every time it is played. The total cost of cards played must not exceed mm. Initially, the win-condition card is placed at the pp-th place in the queue.

You need to find out the maximum number of times the win-condition card can be played, ensuring that the total cost does not exceed mm.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t50001 \le t \le 5000). The description of the test cases follows.

The first line of each test case contains four integers n,k,p,mn,k,p,m (1k,pn50001\le k,p\le n\le 5000, 1m50001\le m\le 5000), denoting the number of cards, the number of cards that are playable at a time, the initial position of the win-condition, and the total energy available.

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1aim1\le a_i\le m) denoting the cost of each card.

It is guaranteed that the sum of nn over all test cases does not exceed 50005000.

Output

For each test case, output one integer in one line, denoting the maximum times the win-condition can be played.

Note

In the first test case, we can only play the first card in the deck, and playing it will use all the energy. Since the win-condition is the second card, we can't play it before energy runs out. Therefore, the answer is 00.

In the second test case, we can play all the cards in the deck. The optimal strategy is obviously only playing the win-condition. Since it costs 11 energy to play and we have 66 energy in total, we can play it 66 times before energy runs out. Therefore, the answer is 66.

In the third test case, we can play cards as follows: (the win condition is colored red)

The initial deck is [2,1,2][2,\color{red}{1},2].

Play the first card: The deck becomes [1,2,2][\color{red}{1},2,2].

Play the first card again: The deck becomes [2,2,1][2,2,\color{red}{1}].

Play the first card once again: The deck becomes [2,1,2][2,\color{red}{1},2].

Play the second card: The deck becomes [2,2,1][2,2,\color{red}{1}].

In the process, we have played the win-condition for 22 times, and we used 66 energy in total. It can be shown that no strategy allows us to play the win-condition more than 22 times with no more than 66 points of energy; therefore, the answer is 22.

In the fourth test case, it can be shown that we can play the win-condition no more than once. This is achievable by always playing the 44-th card in the deck. Therefore, the answer is 11.

Samples

4
2 1 2 42
42 1
3 3 2 6
2 1 2
3 2 2 6
2 1 2
8 4 7 10
3 4 4 2 1 1 4 2
0
6
2
1

在线编程 IDE

建议全屏模式获得最佳体验