I think you are not getting input right due to unknown number of values .You can use string with cin.peek() or stringstream for input then convert value into integer.
The error is only in your assignment for the max. You initialized it with A[0] which is (by then) just an empty array. Since there’s no value inside, the value of A[0] is randomized within the limits of what an int can hold (your first max’s value is EXTRA LARGE).
You can rest easy by just switching A[0] with plain old 0, such as:
max = 0;
Hope it helps.
Tip: since ‘max’ is a reserved variable, you may try switching it with ‘mx’ or any other instead to reduce confusion.
@tpriyanshu90 the error is in “cin>>N” statement. In ur case u are assuming that first value is N but it’s clearly mentioned in the question that first value may and may not be N.
Also i didn’t checked rest of ur logic.
The original value of N became appended to N+1 so the succeeding statements are correct. But I forgot there’s no N given after T, only the N+1 long line for each case…
@tpriyanshu90: Didn’t notice that. The input should be T at first line and then every succeeding lines will contain N+1 integers with N mixed within at random.