Help me in solving WELLLEFT problem

My issue

For third case in example test: 20 6 18
Why is answer 180 instead of 165?
165
= 105 + (20 * 3)
= 1+2+...+14 + (20*3)
= [[(4,1)],[(5,1),(5,2)],...,[(17,1),...,(17,14)],[(18,1),...,(18,20)]...]

My code

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

int main() {
	ll T;
	cin >> T;
	while (T--) {
	    ll N, K, H;
	    cin >> N >> K >> H;
	    ll d = ceil(H / K);
	    if (d > (N - 1)) {
	        cout << "0\n";
	        continue;
	    }
	    ll n = min(N, H - 1) - d;
	    ll answer = (n * (n + 1)) / 2;
	    if (H <= N)
	        answer += (N - H + 1) * N;
	    cout << answer << "\n";
	}
}

Problem Link: Amphibian Escape Practice Coding Problem

you are missing pairs like (17,15) .
you are missing this line from the question : If it reaches a height of H units or greater with this jump, it’s considered to have climbed out of the well, and the process stops.
You are considering the process to stop when frog also slips b units but that’s not the case.dry run it for (17,15) to understand.
you are using k*(A-B) >= h, while it should be k*A - (k-1)*B >= h. Since slipping happens after frog has climbed.

1 Like