For this Question: Newton recently discovered his fourth law of motion, and the cunning Keppler has stolen his research and is planning to publish it before Newton. But Newton has encrypted his research with a unique key, and Keppler doesn't know the key, but he knows that the key is the answer to the following problem. Can you help Keppler get his hands on the key? The problem is as follows:

You are given the weights of M different planets and have to place them in N orbits around the Sun. The i<sup>th</sup> orbit is at a distance of i light years from the Sun. However, in any single orbit, you can place at most one planet; otherwise, the solar system will collapse. The weight of the i<sup>th</sup> planet is w<sub>i</sub>. 

Assume you have placed the i<sup>th</sup> planet on the orbit at distance d<sub>i</sub> from the Sun, where 1 &le; i &le; M and d<sub>i</sub>&ne;d<sub>j</sub> for i&ne;j. The stability of the Solar System is given by the summation of abs(d<sub>i</sub>-d<sub>j</sub>)w<sub>i</sub>w<sub>j</sub> over all pairs (i, j) such that 1 ≤ i < j ≤ M. Here, abs(x) denotes the absolute value of the integer x. Your goal is to place the planets in such a way that the stability of the Solar System is maximized.

Formally, you have to choose M different positions for the M weights in an array of size N. Assume you have placed the i<sup>th</sup> weight in d<sub>i</sub><sup>th</sup> position, where d<sub>i</sub>&ne;d<sub>j</sub> for i&ne;j. Then, the stability of the array is defined as the summation of abs(d<sub>i</sub>-d<sub>j</sub>)w<sub>i</sub>w<sub>j</sub> over all pairs (i, j) such that 1 ≤ i < j ≤ M. You have to find the maximum stability over all possible arrangements.

Using Newton's glorious research, can you help Keppler find this value and become famous?The first line of the input contains two space-separated integers N and M, denoting the number of orbits and number of planets, respectively.

In the next M lines, the  i<sup>th</sup> line contains a single integer w<sub>i</sub>, denoting the weight of the i<sup>th</sup> planet.

<b>Constraints:</b>

2 &le; N &le; 10<sup>6</sup>
2 &le; M &le; min(N,100)
1 &le; w<sub>i</sub> &le; 5000
Print a single integer, the maximum stability over all possible arrangements.
Sample Input 1:
2 2
1
3

Sample Output 1:
3

Explanation:
Put the first planet in first orbit and the second in the second orbit. Then stability = (2-1)*1*3 = 3.

Sample Input 2:
4 2
5
6

Sample Output 2:
90
, I have written this Solution Code:     #include <algorithm>
    #include <iostream>
    #include <limits>
    #include <numeric>
    #include <vector>
     
    constexpr long long inf = std::numeric_limits<long long>::max() / 2;
     
    constexpr int X = 5000;
     
    int main() {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
     
        int n, m;
        std::cin >> n >> m;
     
        std::vector<int> p(m);
        for (auto &e : p) std::cin >> e;
        std::sort(p.begin(), p.end(), std::greater<int>());
     
        long long s = std::accumulate(p.begin(), p.end(), 0);
     
        long long cs = 0;
        std::vector<long long> pd { 0 };
        for (int v : p) {
            cs += v;
     
            int m1 = pd.size() - 1;
            int m2 = m1 + v;
            std::vector<long long> dp(m2 + 1, -inf);
     
            for (int ls = 0; ls <= m1; ++ls) {
                {
                    int nls = ls + v;
                    dp[nls] = std::max(dp[nls], pd[ls] + nls * (s - nls));
                }
                {
                    int nls = ls;
                    int rs = cs - nls;
                    dp[nls] = std::max(dp[nls], pd[ls] + rs * (s - rs));
                }
            }
     
            pd.swap(dp);
        }
     
        int siz = pd.size() - 1;
        for (int ls = 0; ls <= siz; ++ls) {
            pd[ls] += (long long) (n - m - 1) * ls * (s - ls);
        }
     
        std::cout << *std::max_element(pd.begin(), pd.end()) << std::endl;
        return 0;
    }
, In this Programming Language: C++, Now tell me if this Code is compilable or not?