Language: C++

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[5555],c[5555];
int p[5555];
bool visited[5555];

int main(void){
	int n,i,j;
	ll k,x,y,z;
	ll ans = -INFLL;
	std::cin >> n >> x;
	for(i=0; i<n; ++i){
		std::cin >> p[i]; --p[i];
	}
	for(i=0; i<n; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<n; ++i){
		std::fill(visited,visited+n,false);
		std::fill(dp,dp+n,0ll);
		j = i; k = 0ll; dp[0] = 0ll;
		while(!visited[p[j]]){
			visited[p[j]] = true;
			dp[k+1] = dp[k] + c[p[j]];
			j = p[j];
			++k;
		}
		for(j=1; j<=std::min(n,x); ++j){
			y = j/k; z = j%k;
			ans = std::max(ans,dp[k]*y+dp[z]);
		}
		for(j=x-n; j<=x; ++j){
			if(j<=0){
				continue;
			}
			y = j/k; z = j%k;
			ans = std::max(ans,dp[k]*y+dp[z]);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:37: error: no matching function for call to 'min(int&, ll&)'
   52 |                 for(j=1; j<=std::min(n,x); ++j){
      |                             ~~~~~~~~^~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:52:37: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   52 |                 for(j=1; j<=std::min(n,x); ++j){
      |                             ~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:52:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   52 |                 for(j=1; j<=std::min(n,x); ++j){
      |                             ~~~~~~~~^~~~~