#P16647. [GKS 2018 #D] Candies

    ID: 19010 远端评测题 15000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2018前缀和双指针 two-pointerGoogle Kick Start

[GKS 2018 #D] Candies

Problem Description

Supervin loves to eat candies. Today, his favorite candy shop is offering NN candies, which are arranged in a line. The ii-th candy in the line (counting starting from 1) has a sweetness level SiS_i. Note that the sweetness level of a candy might be negative, which means the candy tastes bitter.

Supervin likes to eat sweet candies. However, candies with a combined sweetness level of more than DD would be too much sweetness even for him. Supervin also realises that a candy with an odd sweetness level is "odd", and he does not want to eat more than OO odd candies. In other words, an odd candy is a candy with a sweetness level that is not evenly divisible by 2. Additionally, since Supervin is in a rush, he can only eat a single contiguous subset of candies.

Therefore, he wants to eat a contiguous non-empty subset of candies in which there are at most OO odd candies and the total sweetness level is maximized, but not more than DD. Help Supervin to determine the maximum total sweetness level he can get, or return IMPOSSIBLE if there is no contiguous subset satisfying these constraints.

Input Format

The first line of the input gives the number of test cases, T. T test cases follow. Each test case contains two lines. The first line contains three integers NN, OO, and DD, as described above. The second line contains seven integers X1X_1, X2X_2, AA, BB, CC, MM, LL; these values are used to generate the values SiS_i, as follows:

We define:

  • $X_i = ( A \times X_{i-1} + B \times X_{i-2} + C ) \pmod M$, for i=3i = 3 to NN.
  • Si=Xi+LS_i = X_i + L, for i=1i = 1 to NN.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum total sweetness level Supervin can get, or IMPOSSIBLE if there is no possible contiguous subset satisfying the problem constraints.

2
6 1 1000000000000000
1 1 1 1 0 100 0
6 1 -100
1 1 1 1 0 100 0
Case #1: 13
Case #2: IMPOSSIBLE
3
10 1 8
4 3 4 1 5 20 -10
10 2 8
4 3 4 1 5 20 -10
10 1 8
4 3 4 1 5 20 -19
Case #1: 7
Case #2: 8
Case #3: -5

Hint

In Sample Case #1, the generated array of sweetness values SiS_i is: [11, 11, 22, 33, 55, 88], where the bold and underlined numbers are the odd numbers. Since Supervin can only eat one odd candy, he can get a maximum total sweetness level by taking the fifth and the sixth candies.

In Sample Case #2, the generated array of sweetness values SiS_i is the same as in Sample Case #1. However, this time Supervin cannot eat candies with a total sweetness level of more than 100-100, so no contiguous subset of candies satisfies the constraints.

Note: We do not recommend using interpreted/slower languages for the Large dataset of this problem.

Limits

1T1001 \le T \le 100.

2N5×1052 \le N \le 5 \times 10^5.

0ON0 \le O \le N.

1015D1015-10^{15} \le D \le 10^{15}.

0X1,X2,A,B,C1090 \le X_1, X_2, A, B, C \le 10^9.

1M1091 \le M \le 10^9.

Small dataset (Test set 1 - Visible)

L=0L = 0.

Large dataset (Test set 2 - Hidden)

5×108L0-5 \times 10^8 \le L \le 0.