提交时间:2023-11-19 21:07:06

运行 ID: 111317

#include <bits/stdc++.h> using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; int n,p[N],ans,maxx=-INF; bool tik=0; int price(int m,int d) { if(d==n) { if(tik==1)m+=p[d]; maxx=max(maxx,m); return 0; } if(tik==1) { m+=p[d]; tik=0; price(m,d+1); m-=p[d]; tik=1; price(m,d+1); } if(tik==0) { m-=p[d]; tik=1; price(m,d+1); m+=p[d]; tik=0; price(m,d+1); } } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>p[i]; } price(0,1); cout<<maxx; return 0; }