Language: C++

#include<bits/stdc++.h>
using namespace std;
void print(vector<long long int> &v)
{
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	cout<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int j,n,kk,i;
	cin>>n>>kk;
	long long int a[n];
	long long int b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		cin>>b[i];
	long long int ans=-1000000000000000000;
	for(i=0;i<n;i++)
	{
		long long int t=0,k=a[i]-1;
		vector<int> x(n);
		vector<long long int > v;
		for(j=0;j<n && x[k]!=1;j++)
		{
			t+=b[k];
			x[k]=1;
			v.push_back(t);
			k=a[k]-1;
		}
		if(kk<=v.size())
		{
			t=-1000000000000000000;
			for(j=0;j<kk;j++)
				t=max(t,v[j]);
			ans=max(ans,t);
			continue;
		}
		long long int pp=v[v.size()-1];
		t=-1000000000000000000;
		if(pp>0)
		{
			if(kk%(v.size())==0)
			{
				ans=max(ans,pp*(kk/(v.size())));
				continue;
			}
			//cout<<kk%n<<endl;
			for(j=0;j<kk%(v.size());j++)
			{
				t=max(t,v[j]);
			}
			t=max(t,(long long int) 0);
			t+=pp*((kk/(v.size())));
			ans=max(t,ans);
		}
		else
		{
			for(j=0;j<v.size();j++)
				t=max(t,v[j]);
			ans=max(t,ans);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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