#include <iostream> #include <vector> #include <algorithm> using namespace std;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
int n, w;
cin >> n >> w;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
// 将商品按价格升序排序
sort(a.begin(), a.end());
// 二分查找确定最优的初始优惠券数量k
long long left = 0;
long long right = a.back() + n; // k的上界
auto compute_cost = [&](long long k) {
long long cost = k * w;
for (int i = 0; i < n; ++i) {
long long discount = k + i;
cost += max(0LL, a[i] - discount);
}
return cost;
};
// 三分查找最小值
while (left < right) {
long long mid1 = left + (right - left) / 3;
long long mid2 = right - (right - left) / 3;
long long cost1 = compute_cost(mid1);
long long cost2 = compute_cost(mid2);
if (cost1 < cost2) {
right = mid2 - 1;
} else {
left = mid1 + 1;
}
}
// 检查附近几个点确保找到最小值
long long min_cost = compute_cost(left);
for (long long k = max(0LL, left - 5); k <= left + 5; ++k) {
min_cost = min(min_cost, compute_cost(k));
}
cout << min_cost << endl;
return 0;
}