提交时间:2023-12-16 11:07:51
运行 ID: 116382
#include<iostream> using namespace std; int a,b,c[10005],d,e,f,g,h,i=0; int main() { cin>>a; for(b=1;b<=a;b++) cin>>c[b]; for(b=1;b<=a;b++) for(d=b+1;d<=a;d++) if(c[d]>c[b]) e=e>=c[d]-c[b]?e:c[d]-c[b]; for(f=1;f<=a;f++) { g=0;h=0; for(b=1;b<=f;b++) for(d=b+1;d<=f;d++) if(c[d]>c[b]) g=g>=c[d]-c[b]?g:c[d]-c[b]; for(b=f+1;b<=a;b++) for(d=b+1;d<=a;d++) if(c[d]>c[b]) h=h>=c[d]-c[b]?h:c[d]-c[b]; i=i>=h+g?i:g+h; } cout<<max(e,i); return 0; }