Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18+7107;
int n,a[200005];
ll sum[200005],f[200005][2],dpf[200005][2],dpb[200005][2],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	for(int i=0;i<=n+1;i++) 
		dpf[i][0]=dpf[i][1]=dpb[i][0]=dpb[i][1]=f[i][0]=f[i][1]=INF;
	ans=INF;
	dpf[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		dpf[i][0]=sum[i-1]+((a[i]&1)|(!a[i]));
		dpf[i][1]=min(dpf[i-1][0],dpf[i-1][1])+((a[i]&1)|(!a[i]));
	}
	dpb[n+1][0]=0;
	for(int i=n;i>=1;i--)
	{
		dpb[i][0]=sum[n]-sum[i]+((a[i]&1)|(!a[i]));
		dpb[i][1]=min(dpb[i+1][0],dpb[i+1][1])+((a[i]&1)|(!a[i]));
	}
	f[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		int add=(a[i]&1)^1;
		f[i][0]=min(min(dpf[i-1][0],dpf[i-1][1]),sum[i-1]);
		f[i][1]=min(f[i-1][0],f[i-1][1])+add;
		ans=min(ans,min(f[i][0],max(f[i][1]-add,0))+min(min(dpb[i+1][0],dpb[i+1][1]),sum[n]-sum[i]));
	}
	printf("%lld\n",ans);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:33:44: error: no matching function for call to 'max(ll, int)'
   33 |                 ans=min(ans,min(f[i][0],max(f[i][1]-add,0))+min(min(dpb[i+1][0],dpb[i+1][1]),sum[n]-sum[i]));
      |                                         ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:33:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   33 |                 ans=min(ans,min(f[i][0],max(f[i][1]-add,0))+min(min(dpb[i+1][0],dpb[i+1][1]),sum[n]-sum[i]));
      |                                         ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:33:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   33 |                 ans=min(ans,min(f[i][0],max(f[i][1]-add,0))+min(min(dpb[i+1][0],dpb[i+1][1]),sum[n]-sum[i]));
      |                                         ~~~^~~~~~~~~~~~~~~