#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool artan(const vector<ll>&v){
vector<ll>vc = v;
sort(vc.begin() , vc.end());
if(vc == v) return true;
else return false;
}
bool azalan(const vector<ll>&v){
vector<ll>vcc = v;
sort(vcc.rbegin() , vcc.rend());
if(vcc == v) return true;
else return false;
}
bool eyni(const vector<ll>&v){
for(int i = 0 ; i < v.size() - 1; i++){
if(v[i] == v[i + 1]) return true;
}
return false;
}
int main() {
int n;
cin >> n;
vector<ll>v(n);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
ll total = 0;
set<long long>s(v.begin(), v.end());
if(s.size() == 1) {
cout << n - 1 << endl;
return 0;
}
else if(artan(v) || azalan(v)) {
cout << 0 << endl; return 0;
}
else{
ll maks_zirve = *max_element(v.begin(), v.end());
for(int i = 0; i < n; i++) {
total += min(maks_zirve - v[i], v[i]);
}
}
cout << total << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |