Atenţie! Aceasta este o versiune veche a paginii, scrisă la 2022-02-10 14:14:25.
Revizia anterioară   Revizia următoare  

 

Fişierul intrare/ieşire:minperm.in, minperm.outSursăIIOT 2021-22 Runda 4
AutorGeorge RapeanuAdăugată destefdascalescuStefan Dascalescu stefdascalescu
Timp execuţie pe test0.5 secLimită de memorie131072 kbytes
Scorul tăuN/ADificultateN/A

Vezi solutiile trimise | Statistici

Minperm

The beautiful city of Julcvari decided to host a city tour(online, of course). They have n different attractions, the i`th one having a beauty equal to i. An initial order for the presentation of the attractions has been selected, but the people of Julcvari started worrying that it might not be the best one.

They believe that the best order for visiting the attractions is the one for which the number of pairs of attractions ($i$, j), where i was visited before j but i is more beautiful than j is minimised. But organizing events is not so easy, a lot of paperwork needs to be done in order to change something like this.

So, the host managed to get k swap plans: let l_1, l_2, \ldots{}, l_k be an array of integers representing the swap plans. The host can perform any number of swaps on the initial order, such that the swapped positions are at a distance equal to one of the elements from array l. There is not much time left, so the people of Julcvari ask you for help in finding the best order in which the attractions are presented.

In other words, a permutation of size n and an array of size k with distinct elements are given. You can only perform swaps between positions i and j such that |j - i| is equal to an element of l. What is the permutation with the minimum number of inversions that can be obtained?

Date de intrare

Fişierul de intrare minperm.in ...

Date de ieşire

În fişierul de ieşire minperm.out ...

Restricţii

  • ... ≤ ... ≤ ...

Exemplu

minperm.inminperm.out
This is some
text written on
multiple lines.
This is another
text written on
multiple lines.

Explicaţie

...

Trebuie sa te autentifici pentru a trimite solutii. Click aici

Cum se trimit solutii?