You are given n non-negative integers x1, x2, ..., xn. You are also given a positive integer E. You have to find n non-negative real numbers p1, p2, ..., pn such that p1 · x1 + p2 · x2 + p3 · x3 + .... + pn · xn = E and p1 + p2 + ... + pn = 1.
If it's not possible to find n such numbers, output -1 instead.
Input
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated integers n and E.
- The second line contains n space-separated integers x1, x2, ..., xn.
Output
For each test case, print a single line containing n space-separated real numbers denoting the values of p1, p2, ..., pn. If there is more than one possible solution, you may output any one. If there is no solution, print -1 instead.
When a solution exists, your answer will be considered correct if the absolute value of the expression p1 · x1 + p2 · x2 + p3 · x3 + ... + pn · xn - E doesn't exceed 10-6 and the value of |(p1 + p2 + p3 + ... + pn) - 1| doesn't exceed 10-6.
Constraints
- 1 ≤ T ≤ 105
- 1 ≤ n, E ≤ 103
- 1 ≤ xi ≤ 103
- sum of n over all test cases doesn't exceed 106
Example
Input 3 1 2 1 3 3 1 2 3 4 4 1 2 3 6 Output -1 0 0 1.00 0 0 0.66666666666 0.33333333333
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a[10500],n,e,i,t,b,c,d;
double s1,s2,c1,c2,c3 = 0;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&e);
b = c = d = -1;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==e)
b = i;
else if(a[i]>e)
d = i;
else if(a[i]<e)
c = i;
}
if(b!=-1)
{
s1 = 1;
for(i=0;i<n;i++)
{
if(i!=b)
printf("%.12f%c",c3,i==n-1?'\n':' ');
else
printf("%.12f%c",s1,i==n-1?'\n':' ');
}
}
else if(c!=-1&&d!=-1)
{
c1 = a[c];
c2 = a[d];
s1 = (e-c2) / (c1-c2);
s2 = 1 - s1;
for(i=0;i<n;i++)
{
if(i==c)
printf("%.12f%c",s1,i==n-1?'\n':' ');
else if(i==d)
printf("%.12f%c",s2,i==n-1?'\n':' ');
else
printf("%.12f%c",c3,i==n-1?'\n':' ');
}
}
else
printf("-1\n");
}
return 0;
}