Sprinklers
Difficulty: Hard

Roses are planted in a row and numbered from $1$ to $N$.
The distance between two consecutive roses is $1$ meter.
John wants to automate the watering of these plants and wants to set up some sprinklers in the ground.

The cost for setting up each sprinkler is $S$ coins.
John chooses several roses behind which it is allowed to set up a sprinkler and sets some sprinklers behind them. A sprinkler can water the roses depending on the force of the water jet. Initially it can only water one flower behind which it stands. 
To expand the range of __all__ the sprinklers by $1$ meter John has to pay $Q$ coins. Sprinklers can water roses in both directions. For eg:  A sprinkler with its range increased by 1 meter can water three roses: the rose behind which it stands and the roses to its immediate left and immediate right . A sprinkler can water all the plants within its range.
John wants to water all the plants i.e. no plant should be left dry.

Help John minimize his expenditure on watering the plants. Find the number of sprinklers John needs to buy and determine the amount by which we need to increase each sprinklers range in order to water all the roses in the cheapest way.
Besides that, you should determine the positions at which we need to set up sprinklers.  

**Input Format**  
Input starts with number of test cases $T$. Each test case consists of two lines. 

The first line contains four space-separated integers $N$ (the number of roses), $M$ (the number of allowed positions), $S$ (the cost for setting up 1 sprinkler) and $Q$ (the cost for increasing the range of all the sprinklers by 1 meter). 

The second line contains $M$ indices in ascending order $p_i$ that denote the roses behind which it is allowed to set up a sprinkler.

**Constraints**  
$1 \le T \le 50  $  
$1 \le M \le N \le 10^4$    
$1 \le S, Q \le 10^5$    
$1 \le p_i \le N $    
$p_i \lt p_{i+1}$, for $1 \le i  \lt M $  

**Output Format**  
The answer for each test case is described by two lines.

The first line should contain two integers $B$ - number of sprinklers to buy and $E$ - meters to expand water jet.

The second line holds $B$ numbers in ascending order, denoting the positions of the sprinklers; these set of sprinkler's positions must be a subset of the array _p_.

If more than one solution exists, output any of them.

**Sample Input**  

    3
    7 5 2 5
    1 2 3 6 7
    8 3 1 2
    1 3 8
    10 2 8 2
    4 7
    
**Sample Output**  

    3 1
    1 3 6
    2 2
    3 8
    1 6
    7

**Explanation**  
In the first case, John sets up three sprinklers on positions __1__, __3__ and __6__. Each sprinklers range is one meter, so all roses are reachable. Total price is _11_ coins. Illustration for this test case below.<img src="https://s3.amazonaws.com/hr-challenge-images/5847/1421095441-da3c25a785-drawing.svg" title="drawing.svg" />  
In the second case, two sprinklers on positions __3__ and __8__ cover all roses when the range of the sprinklers is increased to two meters. The total price is _6_ coins.  
In the third case, one sprinkler with range __6__ is the optimal solution. The sprinkler can be placed at position __4__ or __7__ and the total price is _20_. 


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
	#include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int INF = 2000000001;

    int greedySetup(int n, vector<int> & p, int expand)
    {
        int j = 0;
        while (j + 1<p.size() && p[j + 1] - expand <= 1) ++j;
        int cnt = 1;
        while (p[j] + expand<n)
        {
            int temp = j;
            while (j + 1<p.size() && p[j + 1] - p[temp] <= 2 * expand + 1) ++j;
            ++cnt;
        }
        return cnt;
    }

    int greedySetup2(int n, vector<int> & p, vector<int> & sol, int expand)
    {
        int j = 0;
        while (j + 1<p.size() && p[j + 1] - expand <= 1) ++j;
        int cnt = 1;
        sol.push_back(p[j]);

        while (p[j] + expand<n)
        {
            int temp = j;
            while (j + 1<p.size() && p[j + 1] - p[temp] <= 2 * expand + 1) ++j;
            ++cnt;
            sol.push_back(p[j]);
        }
        return cnt;
    }

    void brute(int n, vector<int> & p, int s, int q, vector<int> & sol, int & E)
    {
        int start = max(p[0] - 1, n - p.back());
        for (int i = 1; i<p.size(); ++i)
            start = max(start, (p[i] - p[i - 1]) / 2);

        int minSum = INF;
        int best = -1;

        for (int i = start; i < n; ++i)
        {
            int need = greedySetup(n, p, i);
            if (need*s + i*q<minSum)
            {
                minSum = need*s + i*q;
                best = i;
            }
        }
        greedySetup2(n, p, sol, best);
        E = best;
    }

    void solve(int n, vector<int> p, int s, int q, vector<int> & sol, int & E)
    {
        int start = max(p[0] - 1, n - p.back());
        for (int i = 1; i<p.size(); ++i)
            start = max(start, (p[i] - p[i - 1]) / 2);

        int minSum = INF;
        int best = -1;
        while (start<n)
        {
            int need = greedySetup(n, p, start);

            if (need*s + start*q<minSum)
            {
                minSum = need*s + start*q;
                best = start;
            }
            int l = start;
            int r = n;
            while (r - l>1)
            {
                int m = (l + r) / 2;
                if (greedySetup(n, p, m) != need)
                    r = m;
                else
                    l = m;
            }
            start = r;
        }
        greedySetup2(n, p, sol, best);
        E = best;
    }

    int main() {
        ios::sync_with_stdio(false);
        int _t;
        cin >> _t;
        while (_t--) {
            int _n, _m, _s, _q;
            vector<int> _positions;
            cin >> _n >> _m >> _s >> _q;
            for (int _i = 0; _i<_m; ++_i) {
                int _x;
                cin >> _x;
                _positions.push_back(_x);
            }

            int _E;
            vector<int> _sol;
            solve(_n, _positions, _s, _q, _sol, _E);

            cout << _sol.size() << " " << _E << endl;
            for (int _i = 0; _i<_sol.size() - 1; ++_i)
                cout << _sol[_i] << " ";
            cout << _sol.back() << endl;
        }
        return 0;
    }