不下降序列

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1476

View Code
 1 #include<iostream>
 2 using namespace std ;
 3 int main()
 4 {
 5     int a[10005];
 6     int n, i ;
 7     while(cin>>n)
 8     {
 9         int sum = 0 ;
10         for(i=0; i<n; i++)
11         cin>>a[i] ;
12         for(i=n-1; i>0; i--)
13         {
14             if(a[i]<a[i-1])
15             sum += a[i-1] - a[i] ;
16         }
17         cout<<sum<<endl ;
18     }
19     return 0 ;
20 }
原文地址:https://www.cnblogs.com/yelan/p/2922873.html