#P9499. 「RiOI-2」change

    ID: 10107 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>模拟贪心洛谷原创O2优化洛谷月赛

「RiOI-2」change

Background

Little E finally got back her New Year’s money that her mom had been keeping for her today.

As a far-sighted collector, Little E knows that if she starts collecting things from now on, they will become valuable in the future.

In Little E’s world, there are some banknotes. She knows their future value, but unfortunately, these banknotes can only be exchanged from smaller to larger. What should she do?

Problem Description

You are given nn types of items. For each item ii, its value is viv_i and its quantity is cic_i.

Define the total value as i=1ncivi\sum\limits_{i=1}^n c_i v_i. You may perform some (possibly 00) operations to maximize the total value.

One operation is: choose an ii such that cixic_i \geq x_i, set cicixic_i \gets c_i - x_i, and ci+1ci+1+1c_{i+1} \gets c_{i+1} + 1.

Output the maximum total value modulo 998, ⁣244, ⁣353998,\!244,\!353.

Note: You need to maximize the total value first, and then take modulo 998, ⁣244, ⁣353998,\!244,\!353, rather than maximizing “(total value modulo 998, ⁣244, ⁣353998,\!244,\!353)”.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer sid\text{sid}, indicating the subtask ID of this testdata.

The second line contains a positive integer tt, indicating the number of test cases. For each test case:

  • The input consists of four lines.
  • The first line contains a positive integer nn, the number of types of money.
  • The second line contains nn non-negative integers: v1,v2vnv_1, v_2 \dots v_n.
  • The third line contains nn non-negative integers: c1,c2cnc_1, c_2 \dots c_n.
  • The fourth line contains n1n - 1 positive integers: x1,x2xn1x_1, x_2 \dots x_{n - 1}.

Output Format

Output tt lines. Each line contains one integer, the maximum total value of the items. All answers are taken modulo 998244353998244353.

0
2
2
1 5
5 1
4
10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
11
172998509

Hint

Sample Explanation

For the first test case of the sample, v=[1,5]v=[1,5], c=[5,1]c=[5,1], x=[4]x=[4]. You can choose i=1i=1 and perform one operation. Then c=[1,2]c=[1,2], and the total value is 11+52=111\cdot 1+5\cdot 2=11. It can be proven that this is the maximum.

Constraints and Notes

This problem uses bundled tests.

Below are the special properties of each Subtask. A slash indicates no special restriction in that column.

sid=\text{sid}= n\sum n\le ci,vic_i,v_i\le Special Property Score
11 / Special Property A 55
22 Special Property B 1515
33 Special Property C
44 300300 /
55 20002000 20002000 2020
66 / 1515
77 /
  • Special Property A: xi=109x_i = 10^9.
  • Special Property B: xi=1x_i = 1.
  • Special Property C: all ci,vic_i, v_i are generated uniformly at random in [0,105][0, 10^5]; all xix_i are generated uniformly at random in [1,105][1, 10^5].

For all testdata, 1t1051\le t \le 10^5, 2n2\le n, n2×105\sum n\le 2\times 10^5, 1xi1091\le x_i\le 10^9, 0ci,vi1090\le c_i,v_i\le 10^9.

upd: One more hack testdata set was added, with sid\text{sid} equal to 77.

Translated by ChatGPT 5