Help me in solving MINIMISEMAX problem

My issue

using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int x,y;
cin>>x>>y;
int val1=x/(y+1);
double val2=((double)x/(y+1));
if(val2<=1)
{
cout<<1<<endl;
}
else
{
if(val1==val2)
{
cout<<val1<<endl;
}
else
{
cout<<val1+1<<endl;
}
}
}
return 0;
} . Can anybody tell that why i am getting as wrong answer here

My code

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

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

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

1 Like