whats wrong in the code?
Painters problem
hello @nilotpal
a) use long long in place of int
b) u r asked to take mod of answer but u r not taking.
c) dont sort the array , u are not allowed to change the array order
d) ur check function is wrong. here u need to keep track of sum , if sum+a[i]*t > mid then x++ and sum=a[i]*t
this should ur check logic
can you correct the code and pls explain the logic behind sum+a[i]*t>mid
mid is maximum time a painter can have.
sum is storing work done by a single painter till now ,so if adding next element ie a[i]*t to sum exceeds mid then it means we need another painter. that why if sum + a[i]*t > mid then sum=a[i]*t and x++
otherwise
sum+=a[i]*t;
there is correction in almost everyline ,and also whole check function need to be changed so i would recommend u to try doing urself.
u need to make these changes in ur code
This is correct??
check now->
yeah! got it!! thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.