제출 #1332332

#제출 시각아이디문제언어결과실행 시간메모리
1332332JuanJLKrugomet (COCI25_krugomet)C++20
14 / 70
58 ms436 KiB
#include <bits/stdc++.h>

#define fst first
#define snd second
#define pb push_back
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define forn(i,a,b) for(int i = a; i<b; i++)
#define mset(a,v) memset(a,v,sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;

const int MAXN = 1000;

ll n,k;
ll a[MAXN];
ll s[MAXN];
ll newa[MAXN];

int main(){
    cin>>n>>k;
    forn(i,0,n) cin>>a[i], newa[i]=0;
    forn(i,0,n) cin>>s[i], s[i]--;

    forn(i,0,n){
        ll nd = i;
        forn(j,0,k){
            nd=s[nd];
        }
        newa[nd]+=a[i];
    }

    pair<ll,ll> res = {-1,-1};
    forn(i,0,n){
        res=max(res,pair<ll,ll>{newa[i], (ll)i});
    }

    cout<<res.fst<<'\n';
    cout<<res.snd+1<<'\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...