Language: C++

#include <bits/stdc++.h>
using namespace std;
#define long long int
long long P[5010];
long long C[5010];

signed main() {
  long long N, K;
  cin >> N >> K;
  for (long long i = 1; i <= N; i++) {
        cin >> P[i];
  }
  for (long long i = 1; i <= N; i++) {
        cin >> C[i];
  }
  
  long long nmax = -1000000000;//各Nについてのmax
  long long ntemp = 0;//各Nについての途中得点
  long long allmax = -1000000000;//全部の最大値
  int flag;
  int cnt;

  //全マスについて最大値を計算する
  for (int i = 1; i <= N; i++) {
    nmax = -1000000000;
    ntemp = 0;
    flag = 1;//サイクルを回ったかどうかのフラグ
    cnt = 1;//サイクルの数 最初の１回は動いてからスタート
    int temp = i;//最初のマスを記録
    int now = temp;//現在のマス
    //最初の移動をする
    now = P[now];
    ntemp+= C[now];
    nmax=max(nmax,ntemp);
    allmax = max(allmax, nmax);
    //スタート
    do {
      now = P[now];
      ntemp += C[now];
      nmax = max(nmax, ntemp);
      allmax = max(allmax, nmax);
      cnt++;
      if (cnt == K) {
        flag = 0;//サイクルを回らずに終わった場合
        //cout<<"サイクルを回らずに終わった場合"<<endl;
        break;
      }
    }
    while (now != temp);
    //cout<<now<<" "<<cnt<<"flag"<<flag<<"ntemp"<<ntemp<<endl;
    
    //サイクルを回らずに終わった場合
    if (flag != 1) {
      allmax = max(allmax, nmax);
      continue;
    }
    
    //サイクルした場合
      //サイクル後スコアが減少している場合
    if (ntemp <= 0) {
      //allmax = max(allmax, nmax);
      //cout<<nmax<<"$"<<allmax<<endl;
      continue;
    }
    
    //サイクル後スコアが増加している場合
    if (ntemp > 0) {
      long long sc = K / cnt;//何サイクル回ったか
      //サイクルを回った余りの数　zc
      long long zc = K - sc * cnt;//残り回数を計算
      ntemp=sc*ntemp;
      nmax = max(nmax, ntemp);
      //cout<<"sc"<<sc<<"zc"<<zc<<"ntemp"<<ntemp<<endl;
      for (int j = 0; j < zc; j++) {
        now = P[now];
        ntemp += C[now];
        nmax = max(nmax, ntemp);
      }
      //cout<<nmax<<"*"<<allmax<<endl;
      allmax = max(allmax, nmax);
      continue;
    }
  }
  //cout<<flag<<" "<<cnt<<endl;
  cout << allmax << endl;
  return 0;
}


Compiler output:
a.cc:3:19: error: two or more data types in declaration of 'P'
    3 | #define long long int
      |                   ^~~
a.cc:4:1: note: in expansion of macro 'long'
    4 | long long P[5010];
      | ^~~~
a.cc:3:19: error: two or more data types in declaration of 'C'
    3 | #define long long int
      |                   ^~~
a.cc:5:1: note: in expansion of macro 'long'
    5 | long long C[5010];
      | ^~~~
a.cc: In function 'int main()':
a.cc:3:19: error: two or more data types in declaration of 'N'
    3 | #define long long int
      |                   ^~~
a.cc:8:3: note: in expansion of macro 'long'
    8 |   long long N, K;
      |   ^~~~
a.cc:3:19: error: two or more data types in declaration of 'K'
    3 | #define long long int
      |                   ^~~
a.cc:8:3: note: in expansion of macro 'long'
    8 |   long long N, K;
      |   ^~~~
a.cc:9:10: error: 'N' was not declared in this scope
    9 |   cin >> N >> K;
      |          ^
a.cc:9:15: error: 'K' was not declared in this scope
    9 |   cin >> N >> K;
      |               ^
a.cc:3:19: error: two or more data types in declaration of 'i'
    3 | #define long long int
      |                   ^~~
a.cc:10:8: note: in expansion of macro 'long'
   10 |   for (long long i = 1; i <= N; i++) {
      |        ^~~~
a.cc:10:25: error: 'i' was not declared in this scope
   10 |   for (long long i = 1; i <= N; i++) {
      |                         ^
a.cc:11:16: error: 'P' was not declared in this scope
   11 |         cin >> P[i];
      |                ^
a.cc:3:19: error: two or more data types in declaration of 'i'
    3 | #define long long int
      |                   ^~~
a.cc:13:8: note: in expansion of macro 'long'
   13 |   for (long long i = 1; i <= N; i++) {
      |        ^~~~
a.cc:13:25: error: 'i' was not declared in this scope
   13 |   for (long long i = 1; i <= N; i++) {
      |                         ^
a.cc:14:16: error: 'C' was not declared in this scope
   14 |         cin >> C[i];
      |                ^
a.cc:3:19: error: two or more data types in declaration of 'nmax'
    3 | #define long long int
      |                   ^~~
a.cc:17:3: note: in expansion of macro 'long'
   17 |   long long nmax = -1000000000;//各Nについてのmax
      |   ^~~~
a.cc:3:19: error: two or more data types in declaration of 'ntemp'
    3 | #define long long int
      |                   ^~~
a.cc:18:3: note: in expansion of macro 'long'
   18 |   long long ntemp = 0;//各Nについての途中得点
      |   ^~~~
a.cc:3:19: error: two or more data types in declaration of 'allmax'
    3 | #define long long int
      |                   ^~~
a.cc:19:3: note: in expansion of macro 'long'
   19 |   long long allmax = -1000000000;//全部の最大値
      |   ^~~~
a.cc:25:5: error: 'nmax' was not declared in this scope; did you mean 'fmax'?
   25 |     nmax = -1000000000;
      |     ^~~~
      |     fmax
a.cc:26:5: error: 'ntemp' was not declared in this scope; did you mean 'mktemp'?
   26 |     ntemp = 0;
      |     ^~~~~
      |     mktemp
a.cc:32:11: error: 'P' was not declared in this scope
   32 |     now = P[now];
      |           ^
a.cc:33:13: error: 'C' was not declared in this scope
   33 |     ntemp+= C[now];
      |             ^
a.cc:35:5: error: 'allmax' was not declared in this scope
   35 |     allmax = max(allmax, nmax);
      |     ^~~~~~
a.cc:3:19: error: two or more data types in declaration of 'sc'
    3 | #define long long int
      |                   ^~~
a.cc:68:7: note: in expansion of macro 'long'
   68 |       long long sc = K / cnt;//何サイクル回ったか
      |       ^~~~
a.cc:3:19: error: two or more data types in declaration of 'zc'
    3 | #define long long int
      |                   ^~~
a.cc:70:7: note: in expansion of macro 'long'
   70 |       long long zc = K - sc * cnt;//残り回数を計算
      |       ^~~~
a.cc:70:26: error: 'sc' was not declared in this scope
   70 |       long long zc = K - sc * cnt;//残り回数を計算
      |                          ^~
a.cc:74:27: error: 'zc' was not declared in this scope
   74 |       for (int j = 0; j < zc; j++) {
      |                           ^~
a.cc:85:11: error: 'allmax' was not declared in this scope
   85 |   cout << allmax << endl;
      |           ^~~~~~