Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I was trying to solve this problem: https://open.kattis.com/problems/houselawn I seems to work fine for any test case I can come up with but I get
I was trying to solve this problem:
https://open.kattis.com/problems/houselawn
I seems to work fine for any test case I can come up with but I get wrong aswer upon submission. Any idea what's wrong in my code?
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.ArrayList; public class lawnmower { private static String[] words; private static String[] cand; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); words = in.readLine().split(" "); ArrayListcandidates = new ArrayList<>(); int sqm = Integer.parseInt(words[0]); int movers = Integer.parseInt(words[1]); int minprice = 10000000; for (int i = 0; i < movers; i++) { cand = in.readLine().split(","); String name = cand[0]; int price = Integer.parseInt(cand[1]); int cutRate = Integer.parseInt(cand[2]); int cutTime = Integer.parseInt(cand[3]); int chargeTime = Integer.parseInt(cand[4]); //double cutsPrWeek = (10080*52.0 / (cutTime + chargeTime))/52.0; double cutTimeAvg = 0; double cuts = 0; while(cutTimeAvg <10080*2){ for (int j = 0; j < cutTime; j++) { cutTimeAvg++; } cuts++; // System.out.println(cuts); for (int j = 0; j < chargeTime; j++) { cutTimeAvg++; } } double cutsPrWeek = cuts / 2; //System.out.println(cutsPrWeek); // System.out.println(cutsPrWeek); long sqmPrWeek = (long)cutsPrWeek*cutTime*cutRate; if(sqm <= sqmPrWeek){ if(price==minprice) { candidates.add(name); } else if(price out.println(candidates.get(j)); } } else { System.out.println("no such mower"); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started