1 #include <cstdio> 2 #include <iostream> 3 #define N 100010 4 using namespace std; 5 int n,ans,l,a[N],mx[N]; 6 int main() 7 { 8 freopen("game.in","r",stdin),freopen("game.out","w",stdout),scanf("%d",&n); 9 for (int i=1;i<=n;i++) scanf("%d",&a[i]),mx[n]=a[n]; 10 for (int i=n-1;i;i--) mx[i]=max(mx[i+1],a[i]); 11 for (int i=1;i<=n;i++) if (mx[i]==a[i]) ans+=a[i]*(i-l),l=i; 12 printf("%d",ans); 13 }
原文:https://www.cnblogs.com/Comfortable/p/10339598.html