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

Правка en1, от 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 ^_^

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский So_Cold 2016-09-02 17:16:04 603 Initial revision (published)