# Iarcs BOOK SORTING WA!!!!

can somebody explain why i am getting WA in book sorting ???

Would be helpful if you could provide the testdata…
Here’s the link http://opc.iarcs.org.in/index.php/problems/BOOKSORT
here’s my code

#include
using namespace std;

``````int main()
{
int n,array[200000],value,index1=0,index2 =0;
cin >> n;
for(int i=0;i<n;i++)
cin >> array[i];
for(int i=1;i<n;i++)
{
value = array[i];
for(int j=i-1 ; j>=0 ; j--)
{
if(array[j] > value)
{
index1++;
break;
}
}
}
for(int i=n-2;i>=0;i--)
{
value = array[i];
for(int j = i+1;j<n;j++)
{
if(array[j] < value)
{
index2++;
break;
}
}
}
cout << min(index1, index2);
}``````

Can you give your code

This might also be of help - https://discuss.codechef.com/questions/89275/booksort-iarcs-online-judge

Could help you telling the mistake for WA if you could provide your code.

i forgot to upload it… xD

Test data is available but in something called a test generator program which I don’t understand

I think even if it may be giving WA it should be giving TLE because a n^2 solution does not work here. The correct answer is n-lis(a) where lis means the length of the longest increasing subsequence and you have to implement it in n log n

//