 # Chef and Street Food | CodeChef

all the sample input for the code are right for the problem but it showing WA after the submission plz help
#include<stdio.h>
main()
{
int t,i,j,sale,max,s,p,v,n;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%d %d %d",&s,&p,&v);
sale[j]=(p/(s+1)*v);
}
max=sale;
for(j=0;j<n-1;j++)
{
if(sale[j+1]>sale[j])
{
max=sale[j+1];
}
}
printf("%d",max);
}
}

HERE YOU GO.

``````#include<stdio.h>
main()
{
long long int t,i,j,sale,max,s,p,v,n;
scanf("%lld",&t);
for(i=0;i<t;i++)
{
scanf("%lld",&n);
for(j=0;j<n;j++)
{
scanf("%lld %lld %lld",&s,&p,&v);
sale[j]=(int((p/(s+1)))*v);
}
max=sale;
for(j=0;j<n-1;j++)
{
if(sale[j+1]>max)
{
max=sale[j+1];
}
}
printf("%lld\n",max);
}
}
``````

the only problem is that you used int data type and the last “if” condition was wrong.

1 Like

try coding out this logic
python code:

t=int(input())
for _ in range(t):
n=int(input())
arr=[]
for i in range(n):
s,p,v=map(int,input().split())
res=(p//(s+1))*v
arr.append(res)
#print(arr)
print(max(arr))

1 Like

I am getting wrong answer if i use the following logic:
scanf("%d %d %d",&s,&p,&v);
prof=(v/(s+1)*p);

what’s wrong with this?

bro this problem arises due to the priority of the mathematical equation which makes the division to take place first then the multiplication thus causing error