Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer need to be in Java/python3/c# you are given an array Arr of N integers sorted in Non decreasing order . you want to choose

Answer need to be in Java/python3/c#

you are given an array Arr of N integers sorted in Non decreasing order .

you want to choose 2 subarrays from it where difference between largest and smallest elements is no greater than A in the first sub array and the difference in the second sub array is no greater than B you want sum of sizes of both sub arrays to be maximized

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Problem Statement You are given an array Arr of N integers sorted in a non-decreasing order You want to choose two subarrays from it where the difference between the largest and smallest (first and last) elements is no greater than A in the first subarray, and the difference in the second subarray is no greater than B You want the sum of sizes of both subarrays to be maximized Your task is to find the maximum sum of sizes of a valid combination of subarrays that meet the above conditions. Note It is given that any element can belong to only one subarray Input Format It is given that any element can belong to only one subarray Input Format The first line contains an integer, N, denoting the number of elements in Arr. The next line contains an integer, A, denoting the limit for sum of first subarray The next line contains an integer B, denoting the limit for sum of second subarray Each line i of the N subsequent lines (where 0 si

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago