A. Joey Takes Money
Joey is low on money. His friend Chandler wants to lend Joey some money, but can't give him directly, as Joey is too proud of himself to accept it. So, in order to trick him, Chandler asks Joey to play a game.
In this game, Chandler gives Joey an array () of positive integers ().
Joey can perform the following operation on the array any number of times:
- Take two indices and (.
- Choose two integers and () such that .
- Replace by and by .
In the end, Joey will get the money equal to the sum of elements of the final array.
Find the maximum amount of money Joey can get but print . Why multiplied by ? Because we are never gonna see it again!
It is guaranteed that the product of all the elements of the array doesn't exceed .
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains a single integer () — the length of the array .
The second line contains integers () — the array itself.
It's guaranteed that the product of all doesn't exceed (i. e. ).
For each test case, print the maximum money Joey can get multiplied by .
code of this question ---
void solve()
{
int n;
int res =0;
cin >>n ;
int arr[n];
for ( int i =1 ; i<=n ; ++i )
{
cin >> arr[i];
}
int temp=0;
for(int i=1; i<n ; ++i)
{
temp = arr[1]*arr[i+1];
arr[1]=temp;
arr[i+1]=1;
}
for(int i=1; i<=n; ++i)
{
res+=arr[i];
}
;
cout<<res*2022<<nline;
}


No comments:
Post a Comment