So_Cold's blog

By So_Cold, history, 8 years ago, In English

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 ^_^

  • Vote: I like it
  • +4
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

deleted

  • »
    »
    8 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    This problem is about k iterations of bubble sort, but So_cold's problem is about k iterations of selecting sort.