# Whats wrong in my code, it is giving a runtime error ? https://www.codechef.com/problems/SLUSH .... Drink Slush problem

#include
#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
int no_cust,flav,profit=0;int check_v[100];
cin>>no_cust>>flav;
int arr[flav+1];
for(int i=1;i<=flav;i++)
{
cin>>arr[i];
}
int cust_flav,willing_pay,ok_pay;int count=0;int final_arr[no_cust];
for(int i=0;i<no_cust;i++)
{
final_arr[i]=0;
}
int k=0;int v=1;
int cust=no_cust;
while(cust–)
{
cin>>cust_flav>>willing_pay>>ok_pay;
if(arr[cust_flav]!=0)
{
profit=profit+willing_pay;
arr[cust_flav]=arr[cust_flav]-1;
final_arr[k]=cust_flav;
k++;
}
else
{
profit=profit+ok_pay;
count++;

``````         check_v[v]=k;
k++;
v++;
}
}
int z=1;v=v-1;
for(int i=1;i<=flav;i++)
{
while(arr[i]!=0 && v!=0)
{
final_arr[check_v[z]]=i;
arr[i]--;
count--;
z++;
v--;
}
if(count==0)
break;
}
cout<<profit<<endl;
``````

for(int i=0;i<no_cust;i++)
{
cout<<final_arr[i]<<" ";
}

``````}
return 0;
``````

}

Size of check_v is less(make it at least 1000005, this will eliminate run time error). I don’t understand much of your code. Don’t know if it will give correct result tho.

now its a wrong answer, I don’t know where i have gone wrong!

is your logic correct? Have you read the Editorial? Use that logic and try to code that way.