What's wrong with this solution in the tricky deal (LTIME69B)

Out of the two test cases, this solution passes just one!

import java.io.*;
import java.util.*;

class GFG {
	public static void main (String[] args) {
	    Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		    long a=sc.nextLong();
		    long f=0,c=0;
		    long d2=1;
		    long d1=1;
		    long pro=0;
		    for(int i=1;;i++){
		        if(f-c>0) d1=i;
		        if(f-c<=0) break;
		    System.out.println(d1+" "+d2);

Run the loop from i=0 .

Do sum over all c’s(1+2+4+8+…)i.e. c+=2^i


Here. I have made some changes to your code so that it passes :slight_smile:


  1. you need to do sum of all c. So replace c=(long)Math.pow with c+=(long)Math.pow.

  2. You need to find the day number such that the profit is maximised. For this purpose, I’ve taken another variable d3, to keep track of max profit.

  3. On day i, chef has to pay 2^{i-1}. So replace Math.pow(2,i) with Math.pow(2,i-1).

This passes. Feel free to ask below if you have any more doubts. Hope this helped :slight_smile: