45382023-03-29 13:39:22AblablablaTevefarmcpp17Wrong answer 8/50600ms3828 KiB
#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> teve;
vector<int> elsoVar;

int vizsgal(int helyzet){
    int osszeg = 0;

    for(int i = 0; i < n - 1; i++){
        if(elsoVar[i] == helyzet + 1){
            osszeg += vizsgal(i + 1);
        }
    }

    return max(osszeg, teve[helyzet]);
}

int main()
{
    cin >> n;
    teve.assign(n, 0);
    elsoVar.assign(n - 1, 0);

    for(int i = 0; i < n; i++){
        cin >> teve[i];
    }

    for(int i = 0; i < n - 1; i++){
        cin >> elsoVar[i];
    }

    cout << max(vizsgal(0), teve[0]) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Wrong answer0/03ms1876 KiB
2Wrong answer0/04ms2124 KiB
3Partially correct2/43ms2336 KiB
4Partially correct2/43ms2696 KiB
5Partially correct2/43ms2644 KiB
6Partially correct2/44ms2832 KiB
7Time limit exceeded0/4600ms2500 KiB
8Time limit exceeded0/6566ms2852 KiB
9Time limit exceeded0/6570ms3272 KiB
10Time limit exceeded0/6555ms3400 KiB
11Time limit exceeded0/6583ms3756 KiB
12Time limit exceeded0/6572ms3828 KiB