Please read the new rule regarding the restriction on the use of AI tools. ×

interesting problem that I've been stuck on for a while

Revision en1, by So_Cold, 2016-09-02 17:16:04

I found this interesting problem here
the problem :
We have an array of integer a[1], a[2], ... , a[N] and a number M.

We take a version of selection sort like this:

for i := 1 to M do
    for j := i + 1 to N do
         if (a[i] > a[j]) then swap(a[i], a[j])

After the program end, count the number of swap operator in it.
Limitation:
1 <= M <= N <= 10^5
abs(ai) <= 10^9
any idea for the solution please ?
thanks in advance ^_^

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English So_Cold 2016-09-02 17:16:04 603 Initial revision (published)