I am trying to solve this easy problem http://www.codechef.com/problems/CHEFRP . Whenever i run on IDE it gives me correct output however when i try submitting the answer it shows wrong answer could someone please tell me whats wrong? here is my code

#include

using namespace std;

int main(void) {

```
int t,i,n,flag=1,count;
int *q=NULL;
cin>>t;
while(t--)
{
cin>>n;
q = new int[n];
for(i=0;i<n;i++)
{
cin>>q[i];
}
for(i=0;i<n;i++)
{
if(q[i]>=2)
{
count=count+2;
}
else
{
flag=1;
}
}
cout<<count<<endl;
count=0;
if(flag==0)
{
cout<<"-1";
}
}
return 0;
```

}

You didn’t understood the question properly, the question asks maximum steps it can take to get 2 of every kind. The solution will be **

sum(of all elements in array) - min(element in array) + 2

```
for ele in array:
if ele is less than 2 : flag=1
if flag==0: print sum(array) - min(array) + 2
else print "-1"
```

**Too many mistakes…!!**

Consider the input

**Input:**

2

3

3 2 4

2

2 1

Let us take first test case with **N=3**

your code’s output is **2 +2 +2 =6**

But the correct answer is **3 +2 +4 =9**

**Mistake 1st:-** Statement - “in the worst case so that it is guaranteed that she gets at least two units of each type of ingredient”.

You are not considering the worst case. She gets **at least** two units of each type of ingredient and not **exactly** two units.

Let us take second test case with **N=2**

your code’s output is **2 +0 =2**

But the output should be **-1**

**Mistake 2nd:-** Statement - “get two units of each type ingredient”

When it is not possible to get even two units from each and every unit, then why are you bothering about the count?

**Mistake 3rd:-** When you are not equating/initializing the **flag** equal to zero anywhere in the code. How could you expect it to be zero, to print the answer **-1** ?

**NOTE:-** You need so much practice buddy…!!

Okay thanks a lot I got my mistakes, i am a beginner as you rightly pointed out i need practice. Yes I will practice.