Language: C++

#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll p[n+1],c[n+1],i,x,y,z,j,ans=0,mini=-1e14;
    vector<ll> v[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    for(i=1;i<=n;i++)
    {
        cin>>c[i];
        mini=max(mini,c[i]);
    }
    for(i=1;i<=n;i++)
    {
        x=p[i];
        z=k;
        while(x!=i && z>0)
        {
            v[i].push_back(c[x]);
            x=p[x];
            z--;

        }
        if(z>0)
            v[i].push_back(c[x]);
    }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<v[i].size();j++)
        {
            if(j>0)
                v[i][j]=v[i][j]+v[i][j-1];
            if(j+1<=k)
                ans=max(v[i][j],ans);
        }
        if(v[i][v[i].size()-1]>0)
        {
            x=k%v[i].size();
            y=0;
            z=0;
            //cout<<x<<endl;
            while(y<x)
            {
                z=max(z,v[i][y]);
                y++;
            }
            //cout<<z<<endl;
            ans=max(ans,(z+(v[i][v[i].size()-1])*(k/v[i].size())));
        }
        /*for(auto x:v[i])
            cout<<x<<" ";
        cout<<endl;
        */
    }
    if(ans==0)
        ans=mini;
    cout<<ans<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:20: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   56 |             ans=max(ans,(z+(v[i][v[i].size()-1])*(k/v[i].size())));
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   56 |             ans=max(ans,(z+(v[i][v[i].size()-1])*(k/v[i].size())));
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   56 |             ans=max(ans,(z+(v[i][v[i].size()-1])*(k/v[i].size())));
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~