#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,h;
cin >> n >> h;
int arr[n];
int mxval = 0;
for(int &i : arr){
cin >> i;
mxval=max(mxval,i);
}
multiset<int>pts;
long long m = 1;
long long c = -arr[0];
pts.insert(arr[0]);
pts.insert(arr[0]);
for(int i = 1;i<n;i++){
multiset<int>temp;
int cn = 0;
for(int j : pts){
if(cn>=i){
temp.insert(j+h);
}
else{
temp.insert(j-h);
}
cn++;
}
temp.insert(arr[i]);
temp.insert(arr[i]);
//point addition:
c-=arr[i];
//expansion:
c-=h*m;
m++;
pts=temp;
}
multiset<int>::iterator it = pts.end();
int cn = 0;
while(cn<n){
it--;
c+=*it;
m--;
cn++;
}
cout << m*(*it)+c;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |