Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



/////////////////////GCD//////////////////////
ll gcd(ll a, ll b)
{
	if(b==0) return a;
	return gcd(b, a%b);
}


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int t=1;
	// cin>>t;
	while(t--)
	{
		ll n, k;
		cin>>n>>k;
		vll pe(n+1), c(n+1);
		for(int i = 1; i <= n; i++) cin>>pe[i];
		for(int i = 1; i <= n; i++) cin>>c[i];
		vector<ll> mat[n+1], sum[n+1], maxim[n+1];

		for(int i = 1; i <=n; i++)
		{
			unordered_map<ll, bool> is;
			int j = i;
			while(is[pe[j]]==false)
			{
				mat[i].pb(pe[j]);
				is[pe[j]]=true;
				j = pe[j];
			}
			sum[i].pb(c[mat[i][0]]);
			maxim[i].pb(sum[i][0]);
			for(int k = 1; k < mat[i].size(); k++)
			{
				// ll temp = sum[i].back()+mat[i][]
				sum[i].pb(sum[i][k-1]+c[mat[i][k]]);
				maxim[i].pb(max(maxim[i][k-1], sum[i][k]));
			}
		}
		// for(int i = 1; i <=n; i++)
		// {
		// 	for(auto j:maxim[i])
		// 	{
		// 		cout<<j<<" ";
		// 	}
		// 	cout<<endl;
		// }
		// return 0;
		ll best = llmn, curr = 0;
		for(int i = 1; i <= n; i++)
		{
			ll si = mat[i].size();
			ll div = k/si;
			ll rem = k%si;
			ll sum1 = sum[i][si-1];
			// for(int j = 0; j < sum[i].size(); j++)
			// {
			// 	sum1+=c[maxim[i][j]];
			// }
			// cout<<sum1<<endl;
			// if(div1>0)
			// {
				if(sum1<=0)
				{
					curr = maxim[i][(rem-1+si)%si];
				}
				else
				{
					if(rem!=0)
						curr = max(div*sum, max(0ll, (div-1))*sum1+maxim[i][(rem-1+si)%si]);
				}
			// }
			// if(sum1>0)
			// {

			// }
				// cout<<"curr "<<curr<<endl;
			best = max(best, curr);
		}
		cout<<best<<endl;

	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:213:63: error: invalid operands of types 'll' {aka 'long long int'} and 'std::vector<long long int> [(n + 1)]' to binary 'operator*'
  213 |                                                 curr = max(div*sum, max(0ll, (div-1))*sum1+maxim[i][(rem-1+si)%si]);
      |                                                            ~~~^~~~
      |                                                            |   |
      |                                                            |   std::vector<long long int> [(n + 1)]
      |                                                            ll {aka long long int}