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
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
while (T-->0){
int N = Integer.parseInt(br.readLine());
long maxProfit = -1;
while (N-->0){
String[] line = br.readLine().split(" ");
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);
}
}
}
did that manvi. Please help
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:
myselfrk0:
long maxProfit = -1;
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
Couldn’t see your code. Getting access denied. Can you please paste your code here?
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;
InputReader sc=new InputReader(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){}
}
static class InputReader
{
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream)
{
reader=new BufferedReader(new InputStreamReader(stream),32768);
tokenizer=null;
}
public String next()
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
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
{
str=reader.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}