提交时间:2024-04-02 13:51:28
运行 ID: 141135
# include <bits/stdc++.h> using namespace std ; int a [1001] , g [1001] [1001] , n ; bool isNumber ( char c ) { return ( c >= '0' && c <= '9' ) ; } void GetNum ( int n ) { char c ; for ( int i = 1 ; i <= n ; i ++ ) { int x ; cin >> x ; do { int num = 0 ; while ( isNumber ( c = getchar ( ) ) ) { num = num * 10 + c - '0' ; } g [x] [num] = 1 ; } while ( c != '\n' ) ; } } int main ( ) { cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [i] ; } GetNum ( n ) ; int maxn , Ans = 0 ; for ( int i = n; i >= 1 ; i -- ) { maxn = 0 ; for ( int j = i + 1 ; j <= n ; j ++ ) { if ( g [i] [j] && a [j] > maxn ) { maxn = a [j] ; } } a [i] += maxn ; Ans = max ( Ans , a [i] ) ; } printf ( "%d\n" , Ans ) ; return 0 ; }