I made the following changes and got the right answer.
import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Arrays;
class A
{
public static void main(String args[])throws IOException
{
Scanner input = new Scanner(System.in);
int t =
Thanku so much everyone especially ,Jashanpreet Singh and Xiongqi Zhang.
Finally got the correct answers for both small and large inputs.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving
Jashanpreet is right.
*h* is the counter for the number of yogurts you had for a day.
*max* is the counter for the total number of yogurts you had.
*h* should be incremented when and only when *max* is incremented.
Jashanpreet Singh 于2018年9月19日周三 下午1:38写道:
> In the code snippet:
>
In the code snippet:
* for(int h=1;h<=k;h++)*
*{ if(index==n){break;}
if(g
wrote:
> Thanku so much again for taking the time and effort.
>
> I think to correct my solution I just need to remove the break statement
>
I think your code gives wrong answer on the cases like:
1
5 1
1 1 2 3 4
Its output should be 4 (Day1:a[0], Day2:a[2], Day3:a[3], Day4:a[4]) but
your code gives 1.
Maybe the inner loop is missing the possibility that if current a[index] is
already expired then Lucy can try to eat a[++index] :D
Thanku so much again for taking the time and effort.
I think to correct my solution I just need to remove the break statement in the
else condition to continue checking the next yogurt till full.
I did do that and am still getting incorrect answer.
import java.io.*;
import java.lang.*;
import
You are trying to do greedy for picking yogurt everyday
Your algorithm:
1. Sort all yogurt by their expiry day.
2. Each day, until I am full, I check the next yogurt
2.1 If the yogurt is not expired, I eat them
2.2 If the yogurt is expired, I throw it away and end this day.
The mistakes happen
just make sure you add comments and output statements saying what your trying
to do.
which might help others help you.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send