[https://sapphireengine.com/@/cx264f]
This is my implementation of the question when I submitted it in hackerblocks https://hack.codingblocks.com/app/practice/1/300/problem
3 of my test case passed but 3 did not I am unable to find the issue in my code
Implementation issue
hello @rahulmutreja76 there was problem of constraints only .
as the test cases are larger .
here is the correct code :
#include
using namespace std;
#define int long long int
bool isPossible(int students, int coupons, int perCoupon, int studentCoupon, int mid) {
if (mid * perCoupon <= coupons + (students - mid) * studentCoupon)
return true;
return false;
}
int32_t main() {
int students, coupons, perCoupon, studentCoupon;
cin >> students >> coupons >> perCoupon>>studentCoupon;
int start = 1, end = students, ans = 0;
while (start <= end) {
int mid = (start+end)/2;
if(isPossible(students, coupons, perCoupon, studentCoupon, mid)) {
ans = mid;
start = mid + 1;
}
else
end = mid - 1;
}
cout << ans;
return 0;
}