Language: C++

#include<iostream>
#include<algorithm>

using namespace std;

using ll = long long;

int main() {
	int n, k;
	cin >> n >> k;
	int* p = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> p[i];
		p[i]--;
	}
	ll* c = new ll[n];
	for (int i = 0;i < n;i++) {
		cin >> c[i];
	}
	ll scoa = -1e9;
	int* arrived=new int[n];
	ll* t_scoa = new ll[n];
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			arrived[j] = -1;
			t_scoa[j] = -1e9;
		}
		int index = 1;
		arrived[i] = 0;
		arrived[p[i]] = 1;
		int now = p[i];
		t_scoa[now] = c[now];
		ll scoa_haba=0;
		int haba=0;
		for (;index < k;) {
			if (arrived[p[now]] == 0) {
				scoa_haba = t_scoa[now] + c[p[now]];
				haba = index + 1;
				now = p[now];
				break;
			}
			if (arrived[p[now]] > 0) {
				scoa_haba = t_scoa[now] - t_scoa[p[now]] + c[p[now]];
				haba = index - arrived[p[now]] + 1;
				now = p[now];
				break;
			}
			else {
				t_scoa[p[now]] = t_scoa[now] + c[p[now]];
				now = p[now];
				index++;
				arrived[now] = index;
			}
		}
		if (haba == 0) {

		}
		else {
			int start = now;
			while (1) {
				if (now == i) {
					t_scoa[now] = max(0, scoa_haba * (ll)(k / haba));
				}
				else {
					t_scoa[now] = max(t_scoa[now], t_scoa[now] + scoa_haba * (ll)((k - arrived[now]) / haba));
				}
				now = p[now];
				if (now == start)break;
			}
		}
		for (int j = 0;j < n;j++) {
			scoa = max(scoa, t_scoa[j]);
		}
	}
	cout << scoa << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:58: error: no matching function for call to 'max(int, ll)'
   62 |                                         t_scoa[now] = max(0, scoa_haba * (ll)(k / haba));
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:62:58: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   62 |                                         t_scoa[now] = max(0, scoa_haba * (ll)(k / haba));
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:2:
/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:62:58: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   62 |                                         t_scoa[now] = max(0, scoa_haba * (ll)(k / haba));
      |                                                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~