Submission #689400

#TimeUsernameProblemLanguageResultExecution timeMemory
689400IUA_HasinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
105 ms5332 KiB
#include <bits/stdc++.h> #define endl "\n" #define finp for(int i=0; i<n; i++) #define fknp for(int k=0; k<n; k++) #define yeap cout<<"YES"<<endl #define nope cout<<"NO"<<endl #define inpintn int n; cin>>n #define inpintarrn int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];} #define inpllarrn long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];} #define ll long long using namespace std; int main () { int n; cin>>n; long long ar[n]; long long z=n-1; long long arr[z]; long long l1=0; long long l=0; long long r=0; for (int i=0; i<n; i++){ if(i==0){ cin>>ar[i]; } else { cin>>ar[i]; arr[i-1]=ar[i-1]-ar[i]; } } for (int i=0; i<z; i++){ if(arr[i]<0){ r=r-arr[i]+1; } else if(arr[i]>0){ l1=l1+arr[i]+1; } else if (arr[i]==0){ l1++; r++; } } long long ans=r; long long maxx; for (int i=1; i<z; i++){ if(arr[i-1]>0){ l=l+arr[i-1]+1; } else if(arr[i-1]<0){ r=r+arr[i-1]-1; } else if(arr[i-1]==0){ l++; r--; } if (l<r){ maxx=r; } else { maxx=l; } if (maxx<ans){ ans=maxx; } else { ans=ans; } } if(l1<ans){ cout<<l1<<endl; } else { cout<<ans<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...