Pagini recente » Cod sursa (job #1612374) | Cod sursa (job #434702) | Cod sursa (job #159222) | Cod sursa (job #66201) | Cod sursa (job #1511347)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("barman.in");
ofstream fout ("barman.out");
int n, sol = 2000000000, V[610], P[610], F[610];
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
{
fin >> V[i];
P[i] = V[i];
}
sort (P + 1, P + 1 + n);
for (int k = 1; k <= n; k++)
{
P[0] = P[1];
for (int i = 1; i < n; i++) P[i] = P[i + 1];
P[n] = P[0];
int cost = 0;
for (int i = 1; i <= n; i++)
{
if (P[i] == V[i] || F[i] == k) continue;
for (int j = i + 1; j <= n; j++)
{
if (V[j] == P[j]) continue;
if (V[i] == P[j])
{
cost += (40 + 2 * (j - i));
F[i] = F[j] = k;
break;
}
}
}
sol = min (sol, cost);
}
fout << sol << '\n';
return 0;
}