Cod sursa(job #2062680)

Utilizator RaduNRadu Negovan RaduN Data 10 noiembrie 2017 18:21:43
Problema Barman Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, rez, timp, A[1201], B[601];
    bool truth[601];
    ifstream f("barman.in");
    ofstream g("barman.out");
    f>>n;
    for(int i=1; i<=n; i++)
    {
        f>>A[i];
        B[i]=A[i];
    }
    sort(A+1, A+n+1);
    for(int i=1; i<n; i++)
    {
        A[n+i]=A[i];
    }
    rez=1000000000;
    for(int i=1; i<=n; i++)
    {
        timp=0;
        for(int j=1; j<=n; j++)
        {
            if(A[i+j-1]!=B[j])
                truth[j]=true;
            else
                truth[j]=false;
        }
        for(int j=1; j<=n; j++)
        {
            if(A[i+j-1]==B[j])
                continue;
            else
            {
                for(int k=1; k<=n; k++)
                {
                    if(truth[k]==true && A[i+k-1]==B[j])
                    {
                        truth[k]=false;
                        timp=timp+abs(j-k)+20;
                        break;
                    }
                }
            }
        }
        rez=min(rez, timp);
    }
    g<<rez<<"\n";
    return 0;
}