You are given an array A of N integers. You can do the following two types of operation any (possibly zero) number of times:

Pick two indices i and j(1≤i,j≤N,i≠j). Change A_j:=A_j+A_i and remove the i^th element from the array.
Pick an index i(1≤i≤N). Split A_i into two positive integers X and Y such that X+Y=A_i. Remove the i^{th} element from the array. Append elements X and Y to the array.

Find the maximum number of distinct elements present in the array after performing any number of operations of the above two types.

EXPLANATION:

For each test case, we are given the length of the array and the array of elements.

Since the first operation combines any two value of the array so the array can be reduced to a single element which is the sum of the array elements in this case.

Now the maximum number of unique elements in the array can be easily thought off as the sum of the array can be split in maximum partitions if we start with 1 and go in increasing order till the sum of these values outperforms the array sum.

The last added value minus 1 gives us the maximum possible distinct partitions of the array since the last number will be a repitition.

My idea is that ii break every no. in 1’s and 2’s and afetr that
starting from 1 till sum how mny no. i can make
why i getting wrong
heres my code can you check

cant we just add them all up and then write them as the sum of the first n natural numbers like ,
for the test case
1
4
1 1 3 5
what we can do is
iterate it in the follwing ways
1 1 3 5
2 3 5
5 5
10
4 6
4 3 3
4 3 2 1
this gives us four distinct integers instead of the 3 that is given in the solution
Could someone explain me whats wrong in this…
Thank You to whoever replies to this

here’s my solution O(n)
first I will get the no. of 1 that can be created. i.e sum of array.
Now I arrange the number as : 1, 1+1, 1+1+1, … . from all the 1’s that is present as to form 1,2,3,…k,(some remaining 1)
I need to find k such k(k+1)/2=sum

=> k=(√(8sum+1))/2 - 1/2
floor value of k is the solution.

Hey, the correctness of your solution depends upon what method you are using while splitting the single number back to the array.
Also, the testcase given in the example has the last value as 4, so this is a different case.

Also the method in the editorial is much more efficient as your method will require producing the array itself, which can go upto \sqrt {100000000} under maximum constraints, so the overall complexity is \sqrt{sum Of Elements Of The Array}