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