Submission #689380

#TimeUsernameProblemLanguageResultExecution timeMemory
689380IUA_HasinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1042 ms2097152 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; // ll max(ll a, ll b){ // if(a<b){ // return b; // } else { // return a; // } // } int main () { int t; cin>>t; int j=1; while (j<=t) { int n; cin>>n; int ar[n]; int z=n-1; int arr[z]; int l1=0; int l=0; int 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++; } } int ans=r; int max; // cout<<r<<endl; 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){ max=r; } else { max=l; } if (max<ans){ ans=max; } else { ans=ans; } } cout<<ans<<endl; // cout<<l1<<endl; // cout<<r<<endl; j++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...