Have a look at the code below all three print statements at the end of main function are giving different results, can someone please explain why is it so??
Input :: 4 4 3 4 3 2 1 1 0.3 3 1 4 0.6 5 3 4 2 1 3 5 3 0.8 4 0.6 5 0.3 6 5 1 3 2 4 5 6 4 0.9 5 0.3 2 0.4 6 0.7 3 0.5 4 2 1 2 3 4 2 0.5 4 0.1
void MAIN()
{
int n,m;
cin>>n>>m;
int x=0;
for(int i=1;i<=n;i++)
{
int a;
cin>>a;
if(a!=i)
{
x=i;
}
}
float arr[n+1]={0};
for(int i=1;i<=m;i++)
{
int a;
cin>>a;
float b;
cin>>b;
arr[a]=b;
}
if(x==0)
{
cout<<1<<endl;
return;
}
float p=1.0;
float ans=0;
for(int i=n;i>=x;i-- )
{
ans+=p*arr[i];
p*=(1.0-arr[i]);
}
//printf("%f\n", ans);
cout<<ans<<"\n";
//cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
MAIN();
}
}