Painter problem code

https://ide.codingblocks.com/s/45751

my code only one test case is passing

Hey Anshu, you can check this i have just corrected your condition function and apart from that if you read the problem carefully it is mentioned that you are supposed to return the ans % 10000003.

check for test case
2
3
1 10 15
ans should be 16 but your code is giving 15
check this
https://ide.codingblocks.com/s/46158

The code is wrong as well as the test case is also wrong . Please redo the solution

1 Like

Let me point out the common mistakes people may do;

  1. take the start pointer to be the maximum element in the array.
  2. do not sort the array as the problem statement mentions that the painter can only paint continous blocks.
  3. the time factor “t” should be multiplied at the end of the problem.
  4. Do check each element of the array if it is less than mid, just in case last element of the array in not checked and if it is more than the mid then also your function returns true…which should be false.
    Here is my code.
    https://ide.codingblocks.com/s/269449
    Thank you

why do we take start pointer to max_element and end pointer to sum_elements ??

hey ! so here we have 3 painters that means 1 will paint 10 unit another will paint the 15 unit so total time will be 15 .So , how come the answer is 16.

#include
#include
#define ll long long
#define mod 10000003
using namespace std;
int main()
{
ll n,k,t;
cin>>n>>k>>t;
ll arr[n];
for(ll i = 0 ; i < n ;i++)
{
cin>>arr[i];
arr[i] = (arr[i]*t)%mod;
}

sort(arr, arr+n,greater<int>());
 long long  ans = 0 ;
 for(ll i = 0 ; i < n ;i += k )
{
	ans +=arr[i];
	ans %=mod;
}
cout<<ans;

}
please help me where i am wrong?