Cod sursa(job #2594320)
| Utilizator | Data | 5 aprilie 2020 18:13:39 | |
|---|---|---|---|
| Problema | Barman | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("barman.in");
ofstream g("barman.out");
int n,i,j,a[605],v[605],w[605];
int main(){
f>>n;
for(i=1;i<=n;++i){
f>>a[i];
v[i]=a[i];
}
sort(v+1,v+n+1);
int k=n,sol=1<<30;
while(k--){
int aux=v[1];
for(i=1;i<n;++i)
v[i]=v[i+1];
v[n]=aux;
for(i=1;i<=n;++i)
w[i]=(a[i]==v[i]);
int cost=0;
for(i=1;i<=n;++i)
if(a[i]!=v[i]){
for(j=1;w[j]||a[i]!=v[j];++j);
w[j]=1;
cost+=20+abs(j-i);
}
sol=min(sol,cost);
}
g<<sol;
return 0;
}
