Language: C++

/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll n, kk;
	cin >> n >> kk;
	vector<ll> p(n+1), c(n+1);
	for(int i = 1; i <= n; i++)
		cin >> p[i];
	for(int i = 1; i <= n; i++)
		cin >> c[i];

	vector<ll> res1[n+1];
	for(int i = 1; i <= n; i++)
	{
		vector<bool> done(n+1, 0);
		ll curr = i;
		while(!done[curr])
		{
			res1[i].push_back(c[p[curr]]);
			done[curr] = 1;
			curr = p[curr];
		}
	}
	ll ans[n+1];
	for(int i = 1; i <= n; i++)
		ans[i] = LLONG_MIN;
	for(int i = 1; i <= n; i++)
	{
		ll k = kk;
		vector<ll> v = res1[i];
		ll ans1 = 0, zz = 0, nn = v.size();
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
			zz += v[j];
		}
		k -= min(nn, k);
		ll xx = (k - nn) / nn;
		xx = max(xx, 0);
		ans1 += zz * xx;
		ans[i] = max(ans[i], ans1);
		k -= xx * nn;
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
		}
		k -= min(nn, k);
		for(int j = 0; j < min(k, nn); j++)
		{
			ans1 += v[j];
			ans[i] = max(ans[i], ans1);
		}
	}
	ll fans = LLONG_MIN;
	for(int i = 1; i <= n; i++)
	{
		fans = max(fans, ans[i]);
	}
	cout << fans << '\n';

}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Compiler output:
a.cc: In function 'void test_case()':
a.cc:51:25: error: no matching function for call to 'max(ll&, int)'
   51 |                 xx = max(xx, 0);
      |                      ~~~^~~~~~~
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:3:
/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:51:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |                 xx = max(xx, 0);
      |                      ~~~^~~~~~~
/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:51:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |                 xx = max(xx, 0);
      |                      ~~~^~~~~~~