➤ Problem Link : 573B. Bear and Blocks
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { int n; cin>>n; ll arr[n]; ll a=1; for(int i=0;i<n;i++) cin>>arr[i]; ll ans[n]; ans[0]=1; ans[n-1]=1; for(int i=1;i<n-1;i++) ans[i]=min(ans[i-1]+1,arr[i]); for(int i=n-2;i>=1;i--) { ans[i]=min(ans[i],ans[i+1]+1); a = max(a,ans[i]); } cout<<a; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
➤ Problem Link : 573B. Bear and Blocks
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { int n; cin>>n; ll arr[n]; ll a=1; for(int i=0;i<n;i++) cin>>arr[i]; ll ans[n]; ans[0]=1; ans[n-1]=1; for(int i=1;i<n-1;i++) ans[i]=min(ans[i-1]+1,arr[i]); for(int i=n-2;i>=1;i--) { ans[i]=min(ans[i],ans[i+1]+1); a = max(a,ans[i]); } cout<<a; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!