| 4 | using namespace std; |
| 5 | |
| 6 | int main(){ |
| 7 | int n; |
| 8 | cin>>n; |
| 9 | vector<int> v(n); |
| 10 | for(auto &i:v) cin>>i; |
| 11 | if(n!=1){ |
| 12 | long long count = 0; |
| 13 | for(int i = 0; i<n-1; i++){ |
| 14 | count = count + max(0, v[i]-v[i+1]); //The difference between current_element and next element will be the number of time we have to increment. |
| 15 | |
| 16 | if (v[i+1]<v[i]) v[i+1] = v[i]; // Here we update the next element which is the (i+1)th element, |
| 17 | // because after increment it must be equal to its previous element in account of minimum count. |
| 18 | } |
| 19 | cout<<count; |
| 20 | } |
| 21 | else{ |
| 22 | cout<<"0"; |
| 23 | } |
| 24 | } |