Language: C++

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
bool check(vector<ll>a){
  rep(i,2,a.size()){
    if(a[i]!=a[i-1] && a[i]!=a.size()-1) return false;
  }
  return true;
}
void solve(vector<ll>&a ,ll n,ll k){
  if(k<=0) return ;
  if(check(a)) return;
  vector<ll> pre(n+2);
  rep(i,1,n+1){
    pre[max(i-a[i],1)]++;
    pre[min(n+1,i+a[i]+1)]--;
  }
  rep(i,2,n+2){
    pre[i]=pre[i-1]+pre[i];
  }
  rep(i,1,n+1) a[i]=pre[i];
  k--;
  solve(a,n,k);
}
int main(){
    optimizeIO();
    ll n,k;
    cin>>n>>k;
    std::vector<ll>a(n+1);
    rep(i,1,n+1) cin>>a[i];
    solve(a,n,k);
    rep(i,1,n+1) cout<<a[i]<<" ";
    cout<<endl;
}


Compiler output:
a.cc: In function 'void solve(std::vector<long long int>&, long long int, long long int)':
a.cc:56:12: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, int)'
   56 |     pre[max(i-a[i],1)]++;
      |         ~~~^~~~~~~~~~
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:56:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   56 |     pre[max(i-a[i],1)]++;
      |         ~~~^~~~~~~~~~
/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:56:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |     pre[max(i-a[i],1)]++;
      |         ~~~^~~~~~~~~~