提交时间:2024-04-01 13:52:49
运行 ID: 140933
# include <bits/stdc++.h> using namespace std ; int a [1005] , g [1005] [1005] ; int main ( ) { int n , x , maxn = 0 , ans = 0 ; cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [i] ; } char c; for ( int i = 1 ; i <= n ; i ++ ) { int x ; cin >> x ; do { int num = 0 ; while ( c = getchar ( ) && ( '0' <= c && c <= '9' ) ) { num = num * 10 + c - '0' ; } g [x] [num] = 1 ; } while ( c != '\n' ) ; } for ( int i = n ; i >= 1 ; i -- ) { maxn = 0 ; for ( int j = i + 1 ; j <= n ; j ++ ) { if ( g [i] [j] ) { maxn = max ( maxn , a [j] ) ; } } a [i] += maxn ; ans = max ( ans , a [i] ) ; } cout << ans << endl ; return 0 ; }