Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for(int i=0; i<N; i++) {
        cin >> P[i];
        --P[i];
    }
    vector<int64_t> C(N);
    for(int i=0; i<N; i++) {
        cin >> C[i];
    }

    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        int k = K;
        int now = i;
        map<int,int> mp;
        set<int> st;
        for(int j=0; j<N; j++) {
            mp[now] = j;
            if(mp.count(P[now])) {
                for(auto [key, val]: mp) {
                    if(val >= mp[P[now]]) st.insert(key);
                }
            } else {
                now = P[now];
            }
        }
        int64_t total = 0;
        for(auto e: st) {
            total += C[e];
            // cerr << "total: " << total << endl;
        }

        now = i;
        int64_t point = 0;
        int64_t tmp = 0;
        for(int j=0; j<N; j++) {
            if(k == 0) break;
            if(st.find(now) == st.end()) {
                now = P[now];
                point += C[now];
                tmp = max(point, tmp);
            } else {
                point += max(0L, total) * (k/st.size());
                if(total > 0) k %= st.size();
                if(total <= 0) k = min(k, st.size());
                break;
            }
            --k;
            // cerr << i << ' ' << point << endl;
        }
            // cerr << i << ' ' << point << endl;
        for(int j=0; ; j++) {
            if(k == 0) break;
            --k;
            now = P[now];
            point += C[now];
            tmp = max(point, tmp);
            // cerr << i << ' ' << point << endl;
        }
        // cerr << tmp << endl;
        ans = max(ans, tmp);
    }

    for(int i=0; i<N; i++) {
        ans = max(ans, C[P[i]]);
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:39: error: no matching function for call to 'min(int&, std::set<int>::size_type)'
   61 |                 if(total <= 0) k = min(k, st.size());
      |                                    ~~~^~~~~~~~~~~~~~
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: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:61:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::set<int>::size_type' {aka 'long unsigned int'})
   61 |                 if(total <= 0) k = min(k, st.size());
      |                                    ~~~^~~~~~~~~~~~~~
/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:4:
/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:61:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   61 |                 if(total <= 0) k = min(k, st.size());
      |                                    ~~~^~~~~~~~~~~~~~