33OJ
登录 注册

#P17887. Rain after Summer

    ID: 20670 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>动态规划 DP平衡树O2优化动态规划优化KTT / Kinetic Tournament Tree

Rain after Summer

Background

[NOIP 2018 Junior] Shuttle Bus (Enhanced Version)

Problem Description

Given a non-decreasing sequence of positive integers a1,a2,…,ana_1,a_2,\ldots,a_n of length nn, and an integer mm.

An integer sequence b1,b2,…,bnb_1,b_2,\ldots,b_n is defined to be good if and only if it satisfies the following conditions:

  1. For all 1≤i≤n1\le i\le n, bi≥aib_i\ge a_i;
  2. Sort the sequence bb in ascending order and denote the result by c1≤c2≤⋯≤cnc_1\le c_2\le\cdots\le c_n; then for all 2≤i≤n2\le i\le n, either ci=ci−1c_i=c_{i-1} or ci−ci−1≥mc_i-c_{i-1}\ge m.

Find the minimum value of ∑i=1nbi\sum_{i=1}^{n}b_i over all good sequences bb.

Input Format

This problem contains multiple test cases.

The first line of the input contains an integer TT, the number of test cases.

Then TT test cases follow. For each test case:

  • The first line contains two positive integers n,mn,m.
  • The second line contains nn non-decreasing integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output Format

For each test case, output one line containing a single non-negative integer, the minimum value of ∑i=1nbi\sum_{i=1}^{n}b_i over all good sequences bb.

2
10 7
12 18 23 24 29 40 41 45 50 60
3 99
1 1 1
357
3

Hint

【Constraints】

This problem uses bundled testing.

  • Subtask 1 (10 pts): m,ai,∑n≤500m,a_i,\sum n\le 500.
  • Subtask 2 (25 pts): ∑n≤5000\sum n\le 5000.
  • Subtask 3 (20 pts): ∑n≤1.5×105\sum n\le 1.5\times 10^5.
  • Subtask 4 (20 pts): ∑n≤3×105\sum n\le 3\times 10^5.
  • Subtask 5 (25 pts): ∑n≤106\sum n\le 10^6.

For all testdata, it is guaranteed that 1≤n,∑n≤106,1≤ai,m≤1091\le n,\sum n\le 10^6,1\le a_i,m\le 10^9, and the sequence aa is non-decreasing.

Translated by QwenWork