Language: C++

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1000000000 + 7;
const string abc = "abacaba";

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    long long res = -1000000000;
    for (int s = 0; s < n; s++) {
        int t = s;
        long long cnt = 0;
        long long local_mx = -1000000000;
        vector<long long> v;
        do {
            t = p[t];
            cnt += c[t];
            v.push_back(cnt);
            res = max(res, cnt);
            local_mx = max(local_mx, cnt);
        } while (t != s);
        long long mx = -1000000000;
        for (int i = 0; i < k % v.size(); i++) {
            mx = max(mx, v[i]);
        }
        if (cnt > 0) {
            res = max(res, cnt * (k / v.size()) + mx);
            res = max(res, cnt * max(0, (k / (int)v.size() - 1)  ) + local_mx);
        } else {
            if (k > v.size()) {
                res = max(res, local_mx);
            } else {
                res = max(res, mx);
            }
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//    int t;
//    cin >> t;
//    for (int tt = 0; tt < t; tt++) {
//        solve();
//    }
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:37:22: error: no matching function for call to 'max(long long int&, long long unsigned int)'
   37 |             res = max(res, cnt * (k / v.size()) + mx);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:37:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   37 |             res = max(res, cnt * (k / v.size()) + mx);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:37:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   37 |             res = max(res, cnt * (k / v.size()) + mx);
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~