I am not able to find my mistake, please help? (DIET)

https://www.codechef.com/viewsolution/28363480

That’s not a link to your submission :slight_smile:

2 Likes

https://www.codechef.com/viewsolution/28363480

1 Like

Consider the testcase:

2                                                       
10 5
1
5
2
1
1
1
1
1
1
1
5 1
10
10
10
10
10
3 Likes

Add (arr[i] - k) to count. If count goes below 0, it means that he couldn’t eat protein on that day. So “i” is the day on which he didn’t eat protein. If the whole loop runs without getting broken, then it means it didn’t go below 0 and he ate protein everyday

 public static void main (String[]args) throws java.lang.Exception
  {
    // your code goes here
    Scanner in = new Scanner (System.in);
    int t = in.nextInt ();
    for (int i = 0; i < t; i++)
      {
        int n=in.nextInt();
        int k=in.nextInt();
        int[] a = new int[n];
        Boolean eat=true;
        int cnt=0;
        for (int j = 0 ; j < n ; j++)
        {
         a[j]=in.nextInt();   
        }
        for (int j = 0 ; j < n ; j++)
        {
            cnt+=a[j]-k;
            if (cnt<0)
            {
                System.out.println("NO "+(j+1));
                eat=false;
                break;
            }
            
        }
        if (eat) System.out.println("YES");
      }
  }
1 Like

thanks a lot!:smiley: