ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1026. Questions and Answers

O(n*max(k))
Posted by Madhav 13 Jun 2008 03:30
does a program with order O(n*max(K)) can get accepted.
A modified version of bubble sort can do this.Note that
after k passes bubble sort has first k maximum elements.
If u find maximum value of index that is being queried and calling the below function with that maximum value will do the trick for you.Try submitting the problem using this idea.I haven't submitted by this idea
for(i=0;i<=k;i++)
    for(j=i+1;j<n;j++)
          if(a[i]>a[j]) swap(a[i],a[j]);