Deepak and his journey Greedy

Giving wrong answer. So can anyone kindly help to find the bug?

@Kinjal Try using long long int in your code.

I did but still no change.

long long int minCost=minCostPerLitre*litreRequired[0];

and I haven’t use long long int in other variables in this code because,

1 ≤ T ≤ 5
1 ≤ N ≤ 10^5
1 ≤ C[i], L[i] ≤ 10^5

https://ide.codingblocks.com/s/344360 look at comments here.

Why this Array should be in long long although it’s range like 1 ≤ C[i], L[i] ≤ 10^5?
It’s not surplus the range of ‘int’.
vector<long long>costPerLiter(n);

in case minCostPerLitre*litreRequired[i]; this multiplication increases int limit so one of them must be long long int,but in just above of this you are calculating minimum of minCost with CostPerlitre so both must be long long int.

1 Like

I understood here, why you took long long int and it’s also my fault to not seeing the multiple operation. But, in here

I think, I’m calculating minimum of minCostPerLitre and CostPerLitre[i], so both can be int because there is no multiplication operation between these variables, right!!!

minCostPerLitre=min(minCostPerLitre,costPerLiter[i]);

PS. I know, your way of doing, given the right output but I just wanted to know that WHY!

int minCostPerLitre=costPerLiter[0]; 

long long minCost=minCostPerLitre*litreRequired[0];

is it not okay!! because here implicit type conversion will be done by compiler, right!!

Sorry bhaiya…I understood what you’re saying now.