 # AC on smaller constraint but WA on bigger constraint

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

long long int check(long long int mid, long long int h[], long long int r[], long long int w, long long int n, long long int l)
{
long long int temp = 0;
for(long long int i = 0; i < n; i++)
{
if((h[i] + (long)((long)r[i] * (long)mid)) >= l)
{
temp += (h[i] + (long)((long)r[i] * (long)mid));
}
}
if(temp >= w) return 1;
else return 0;
}
int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);

long long int n, w, l;
cin >> n >> w >> l;

long long int h[n];
long long int r[n];

for(long long int i = 0; i < n; i++) cin >> h[i] >> r[i];

long long int low = 0;
long long int high = 1000000007;

long long int mid;
long long int mini = 1000000007;
while(low <= high)
{
mid = low + ((high - low)/2);
if(check(mid, h, r, w, n, l))
{
mini = min(mini, mid);
high = mid-1;
}
else
{
low = mid+1;
}
}
cout << mini << "\n";
return 0;
}

``````

This code is getting AC for smaller constraints but WA on larger constraints. Why so? I have tried checking overflows, data types but still not able to catch errors. What else I can do make this code work for larger constraints??

It’s a good idea to look at editorial before posting ,
Just look at the pitfall section of this

1 Like

I should have read the editorial. It was pretty clear, it makes sense now. Thanks.

1 Like