1 #include<cstdio> 2 #define MAXN 100010 3 typedef __int64 LL; 4 struct node 5 { 6 LL w,h; 7 int x,y; 8 }; 9 node st[MAXN]; 10 int main() 11 { 12 node temp; 13 LL ans,wide; 14 int n,i,top,x,y,R; 15 while(~scanf("%d",&n)) 16 { 17 ans=top=-1; 18 for(i=0;i<n;i++) 19 { 20 scanf("%I64d",&temp.h); 21 temp.w=temp.h; 22 temp.x=temp.y=i; 23 if(top>-1) 24 R=st[top].y; 25 for(wide=0;top>-1&&st[top].h>=temp.h;top--) 26 { 27 wide+=st[top].w; 28 if(wide*st[top].h>ans) 29 { 30 ans=wide*st[top].h; 31 x=st[top].x; 32 y=R; 33 } 34 } 35 if(wide) 36 { 37 temp.w+=wide; 38 temp.x=st[top+1].x; 39 } 40 st[++top]=temp; 41 } 42 if(top>-1) 43 { 44 R=st[top].y; 45 for(wide=0;top>-1;top--) 46 { 47 wide+=st[top].w; 48 if(wide*st[top].h>ans) 49 { 50 ans=wide*st[top].h; 51 x=st[top].x; 52 y=R; 53 } 54 } 55 } 56 printf("%I64d\n%d %d\n",ans,x+1,y+1); 57 } 58 return 0; 59 }