MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CSES_Problems/Increasing_Array/solution.cpp:6–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4using namespace std;
5
6int 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}

Callers

nothing calls this directly

Calls 1

maxFunction · 0.85

Tested by

no test coverage detected