Help me in solving MINIMISEMAX problem

My issue

i found other solution after contest many of them are writting this soluion:

max((x1-y2),ceil(x/(y+1)))

anyone please explain how this will minimize the maximum sum of subarray.
for example:
x=50, y=10
according to above solution output will be 30 which is wrong clearly rather it should be only ceil(x/(y+1)) i.e. output would be 5…

My code


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

int main() {
	// your code goes here
	int t;
    cin>>t;
    while(t--){
        double x,y;
        cin>>x>>y;
        if(x<=y)
        cout<<1<<endl;
        else{
            cout<< ceil(x/(y+1))<<endl;
        
        }
    }
	return 0;
}

Problem Link: Minimise Maximum Subarray Sum Practice Coding Problem - CodeChef

Consider the sequence 1 1 1 -2 1 1 1 , the max subarray sum here is not 3 but 4.
Crossing the -2 is beneficial as we still have +1.
similarly if >2 consecutive 1’s are present, they will have advantage over a -2 for maximising sum.

1 Like

I’m not getting what you are explaining

but for this example:
1 1 1 -2 1 1 1
minimize the maximum subarray sum will be 3 not 4.
how you are saying it is 4.

Is not the entire array also a subarray of itself? :slightly_smiling_face:

2 Likes

ohh ya…
my bad I don’t why I’m ignoring the entire array…
thanks for the explanation…

1 Like

Right