Problem Link: FORESTGA Problem - CodeChef
My Code:
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
using lld = long double;
const int MOD = 1e9+7;
const ll INF = 1e18;
const int MAXN = 1e5+5;
int n;
double w, l, r[MAXN], h[MAXN];
bool check(double x) {
double total = 0;
for(int i=0; i<n; i++) {
double height = h[i]+r[i]*x;
if(height >= l) total += height;
if(total >= w) return true;
}
return false;
}
int main() {
FASTIO
cin >> n >> w >> l;
for(int i=0; i<n; i++) {
cin >> h[i] >> r[i];
}
ll low = 0, high = 1e18+5, ans = 0;
for(int i=0; i<=150; i++) {
ll mid = low+(high-low)/2;
if(check((double) mid)) {
ans = mid;
high = mid;
}
else {
low = mid;
}
}
cout << ans << "\n";
return 0;
}
The problem is that I am getting a WA in 15th task of 2nd subtask. Can anybody please help me?