# https://www.codechef.com/LRNDSA02/problems/STFOOD

https://www.codechef.com/LRNDSA02/problems/STFOOD

getting WA plz help

``````    /* package codechef; // don't place package name! */
``````
``````    import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{

while (T-->0){
long maxProfit = -1;

while (N-->0){
long S = Integer.parseInt(line[0]);
long V = Integer.parseInt(line[1]);
long P = Integer.parseInt(line[2]);
long profit = (P/(S+1))*V;

if(maxProfit < profit){
maxProfit = profit;
}

}
System.out.println(maxProfit);
}
}
}
``````

2 Likes

consider this portion of the problem statement:

the number of these people p is not divisible by the number of these stores s, then only âŒŠ\dfrac{p}{s}âŒ‹ people will buy food from Chef.

Use Math.floor() to implement greatest integer function.
P.S.: Donâ€™t forget to explicitly typecast it to long (in your code)

Next problem:

The daily profit canâ€™t be negative! It must be initialised to 0.
Hope you got it!
You can refer to my code if you wish to.

1 Like

Honestly, this question is phrased very poorly and vaguely.

Iâ€™m so sorry . Just forgot that itâ€™s termed as an ongoing contest.
Here you go.

``````import java.io.*;
import java.util.*;
class Codechef
{
public static void main (String[] args) throws IOException
{
try
{
InputStream in=System.in;
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int max=0;
while (n-->0)
{
int s=sc.nextInt(); //stores
int p=sc.nextInt(); //people
int v=sc.nextInt(); //value
int x=v*(int)(Math.floor(p/(s+1)));
//System.out.println(x);
if (x>max)
max=x;
}
System.out.println(max);
}
}
catch (Exception e){}
}

{
public StringTokenizer tokenizer;
{
tokenizer=null;
}
public String next()
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public float nextFloat()
{
return Float.parseFloat(next());
}
public  String nextLine()
{
String str="";
try
{