Roy And Ropes (HackerEarth)
Dynamic Programming,Easy
Solution:-
using namespace std;;
#define MAX 1000010
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
int arr[MAX],upper[MAX],lower[MAX];
int max_val(int a,int b,int c)
{
if(a>=b && a>=c)
return a;
if(b>=a && b>=c)
return b;
return c;
}
int main()
{
int tc;
int l;
cin>>tc;
int maxu,maxl;
while(tc--)
{
maxu=maxl=INT_MIN;
cin>>l;
f(i,1,l-1)
{
cin>>upper[i];
if(upper[i]+i>maxu)
maxu=upper[i]+i;
}
f(i,1,l-1)
{
cin>>lower[i];
if(lower[i]+i>maxl)
maxl=lower[i]+i;
}
cout<<max_val(maxu,maxl,l)<<endl;
}
return 0;
}
No comments:
Post a Comment