提交时间:2023-12-16 08:37:01

运行 ID: 116127

# include <bits/stdc++.h> using namespace std ; int prc [114514] ; long long sum = -114514 ; int n ; void dfs ( int dy , long long sm , bool flg ) { if ( dy > n ) { sum = max ( sum , sm ) ; return ; } else if ( flg ) { dfs ( dy + 1 , sm + prc [dy] , false ) ; } else { dfs ( dy + 1 , sm - prc [dy] , true ) ; } dfs ( dy + 1 , sm , flg ) ; } int main ( ) { cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> prc [i] ; } dfs ( 1 , 0 , false ) ; cout << sum << endl ; return 0 ; }