Help me in solving WELLLEFT problem

My issue

i’m checking the condition if(A+(A-B)*(K-1)>=H) and increasing count, in two for loops what is wrong in this.

My code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    long long N, K, H;
        cin >> N >> K >> H;
        long long count = 0;
        for (long long A = 1; A <= N; ++A) {
            for (long long B = 1; B<= A; ++B) {
                if(A+(A-B)*(K-1)>=H) count++;
            }
        }
        cout<<count<<endl;
	}

}

Problem Link: Amphibian Escape Practice Coding Problem

Bro you are solving problem in O(n^2) which will give you TLE

im getting wrong output not tle.

You write B <= A in the inner loop, but the constraints only state that B \leq N. Notice that in the second sample test case, (4,5) is a solution.

Also note that (4,5) does not satisfy the condition you have written inside the loops.

1 Like