I'am new to C++ just had this unexpected error with using max function, where I pass arguments of type long long and int
When i pass (int,int) as arguments or (long long,long long) it works fine but not with (long long,int)
ll painter(int board[],int n,int k)
{
ll s = 0,total_min;
ll ans;
for(ll i = 0;i < n;i++)
{ total_min += board[i];
s = max(s,board[i]);
}
This is the error showing
prog.cpp:39:25: error: no matching function for call to 'max(int&, long long int&)
s =max(s,board[i]);"
maxexpects the two arguments to be of the same type, and because the usual arithmetic conversion rules don't apply when calling a template function. Just add a cast, and don't use typedefs likell.ll s = *std::max_element(board, board+n); ll total_min = std::accumulate(board, board+n, 0);(assumingnis never 0). Another aside: you don't initialisetotal_min, so your program has undefined behaviourstd::max()does not.