940D. Alena And The Heater - Codeforces Solution C++

  Problem Link : 940D. Alena And The Heater 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n;
	cin>>n;
	ll arr[n+1];
	char b[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];

	ll lmin=-1*pow(10,9),lmax=1*pow(10,9);
	ll rmin=-1*pow(10,9),rmax=1*pow(10,9);
	bool flag=1;
	for(int i=5;i<=n;i++)
	{
		if(b[i]==b[i-1])
			continue;
		if(b[i]=='0')
		{
			rmax=min(rmax,min(arr[i-4],min(arr[i-3],min(arr[i-2],min(arr[i-1],arr[i]))))-1);
			

		}
		else
		{
			lmin=max(lmin,max(arr[i-4],max(arr[i-3],max(arr[i-2],max(arr[i-1],arr[i]))))+1);
			
		}
	}

	cout<<lmin<<" "<<rmax;



}

 

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!!