Last active
November 25, 2024 18:56
-
-
Save KrishGarg/1dc11156bd0a51298db05ba74ce5c225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
long long n, h, k; | |
cin >> n >> h >> k; | |
long long hi[n]; | |
long long gi[n]; | |
for (int i = 0; i < n; i++) | |
{ | |
cin >> hi[i]; | |
} | |
for (int i = 0; i < n; i++) | |
{ | |
cin >> gi[i]; | |
} | |
// binary search | |
long long r = 1e9; | |
long long l = 0; | |
long long ans = 1e9; | |
while (l <= r) | |
{ | |
long long t = floor((l + r) / 2); | |
long long woodCanCollect = 0; | |
for (long long i = 0; i < n; i++) | |
{ | |
long long heightNow = hi[i] + (gi[i] * t); | |
if (heightNow > h) | |
{ | |
woodCanCollect += heightNow; | |
} | |
} | |
if (woodCanCollect >= k) | |
{ | |
ans = t; | |
r = t - 1; | |
} | |
else | |
{ | |
l = t + 1; | |
} | |
} | |
cout << ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment