Advanced DP (Bitmask, Digit, Tree DP)
Count the integers k with 1 <= k <= N whose decimal digits add up to exactly S.
One line with N and S.
Print one integer: how many integers from 1 to N have digit sum S.
1 <= N <= 10^18 0 <= S <= 200 The answer is at most N, so it fits in a signed 64-bit integer.
1000 ms256 MB
100 1
3
The numbers 1, 10 and 100.
99 9
10
The numbers 9, 18, 27, 36, 45, 54, 63, 72, 81 and 90.