Pagini recente »
Baraj Yakuția 2014
|
Clasament 2018_03_24_a_6_a
|
OJI 2023 Clasa a VI-a - Antrenament - FFA v2.1
|
Borderou de evaluare (job #122007)
|
Cod sursă (job #567720)
Cod sursă (job
#567720)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("lanterna.in");
ofstream fout("lanterna.out");
typedef long long ll;
inline void min_self(ll& a, ll b) {
a = min(a, b);
}
int 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());
ll cost = (ll)a[0] * (N - 2);
for(int i = 1; i < N; ++i)
cost += a[i];
ll 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;
}