Pagini recente »
Clasament test_2000
|
2020-01-23-clasa-7-tema-18-optionala
|
olimpiada_pe_scoala_9_2018
|
Monitorul de evaluare
|
Cod sursă (job #567718)
Cod sursă (job
#567718)
#include<bits/stdc++.h>
#define int long long
using namespace std;
ifstream fin("lanterna.in");
ofstream fout("lanterna.out");
inline void min_self(int& a, int b) {
a = min(a, b);
}
int32_t main() {
fin.sync_with_stdio(false);
fout.sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
int N;
fin >> N;
vector < int > a(N);
for(int& x : a)
fin >> x;
sort(a.begin(), a.end());
int cost = a[0] * (N - 2);
for(int i = 1; i < N; ++i)
cost += a[i];
int ans = cost;
for(int k = N - 2; k > 1; k -= 2) {
cost -= a[k] + a[0] - 2 * a[1];
min_self(ans, cost);
}
fout << ans;
}