My issue
pls help me in finding error in my logic.
i calulated the max nd min element and give the ans = max(d + x * (n - 1), c) why it is wrong?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
vector<long long> h(n);
long long c = LLONG_MIN;
long long d = LLONG_MAX;
for (int i = 0; i < n; i++) {
cin >> h[i];
c = max(c, h[i]);
d = min(d, h[i]);
}
long long ans = max(d + x * (n - 1), c);
cout << ans << endl;
}
return 0;
}
Problem Link: Monster Monster Practice Coding Problem