Hi I have written this code but while submitting it is failing for all the cases. But I am getting the answer with the given case and a few more cases

#include<bits/stdc++.h>
#include
#include
using namespace std;
int compare(int a, int b)
{
return a > b;
}
bool canpaint(int n, int k, int t, int ar[], int mid)
{ //n -boards k -painters t-time/board
int painter = 1;
int painted = 0;
for (int i = 0; i < n; i++)
{
if ((ar[i]t) + painted > mid)
{
painter++;
if (painter > k)
return false;
painted = ar[i] * t;
}
else
{
painted += ar[i] * t;
}
}
//cout << painted << endl;
//cout << "painted - " << painted << " Painter - " << painter << " mid - " << mid << endl;
return true;
}
int main()
{
/
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);//redirects standard input
freopen(“output.txt”, “w”, stdout);//redirects standard output
#endif*/
int n, k, t; //n - size of array , k - number of painters , t- time taken by each painter to paint one single board
cin >> n >> k >> t;
int ar[n];

for (int i = 0; i < n; i++)
{
	cin >> ar[i];
}
sort(ar, ar + n, compare);
int ans = INT_MAX;

// int *m = std::max_element(ar, ar + n);
int e = 1000, s = 0;
while (s <= e)
{
int mid = s + (e - s) / 2;
if (canpaint(n, k, t, ar, mid))
{
ans = min(mid, ans);
// cout << " ans - " << ans << endl;
//ans = mid;
e = mid - 1;
}
else
{
s = mid + 1;
}
}
cout << ans << endl;
}

multiply the answer with t later instead, start ans with 0