Pagini recente »
Rating Roxana MS (roxannemafteiu)
|
Monitorul de evaluare
|
Monitorul de evaluare
|
Borderou de evaluare (job #366942)
|
Cod sursă (job #692078)
Cod sursă (job
#692078)
/*
Avem un numar optim de 2*(n-1)-1 mutari
*/
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream cin("lanterna.in");
ofstream cout("lanterna.out");
long long int n;
vector<int> t;
void citire()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
t.push_back(x);
}
}
int main()
{
citire();
sort(t.begin(), t.end());
if (n == 0)
cout << 0;
else if (n == 1)
cout << t[0];
else if (n == 2)
cout << t[1];
else
{
int suma = 0;
for (int i = 1; i < n; i++)
suma += t[i];
int total = (n - 2) * t[0] + suma;
int x = n;
int auxiliar = 2 * t[1] - t[0];
while (t[x - 2] > auxiliar)
{
total -= t[x - 2] - auxiliar;
x -= 2;
}
cout << total;
}
return 0;
}