Language: C++

#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=unsigned long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    ll n,X;cin>>n>>X;
    vector<ll> x(n+10),sum(n+10);
    for(int i=1;i<=n;i++){
        cin>>x[i];
        sum[i]=sum[i-1]+x[i];
    }
    ll ans=LINF;
    for(ll k=1;k<=n;k++){
        ll s=0,c=1;
        s+=(sum[n%k]-sum[0])*(n/k+c+1LL)*(n/k+c+1LL);
        for(ll i=n%k+k;i<=n;i+=k){
            --c;
            s+=(sum[i]-sum[i-k]-sum[i-k]+sum[max(0LL,i-2*k)])*(n/k+c+1LL)*(n/k+c+1LL);
        }
        s+=(n+k)*X;
        s+=sum[n]-sum[n-k];
        ans=min(ans,s);
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:49: error: no matching function for call to 'max(long long int, ll)'
   27 |             s+=(sum[i]-sum[i-k]-sum[i-k]+sum[max(0LL,i-2*k)])*(n/k+c+1LL)*(n/k+c+1LL);
      |                                              ~~~^~~~~~~~~~~
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:27:49: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'll' {aka 'long long unsigned int'})
   27 |             s+=(sum[i]-sum[i-k]-sum[i-k]+sum[max(0LL,i-2*k)])*(n/k+c+1LL)*(n/k+c+1LL);
      |                                              ~~~^~~~~~~~~~~
/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:27:49: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |             s+=(sum[i]-sum[i-k]-sum[i-k]+sum[max(0LL,i-2*k)])*(n/k+c+1LL)*(n/k+c+1LL);
      |                                              ~~~^~~~~~~~~~~