Need help in CSES — Two Sets II: Confusion in usage of mod

Правка en1, от yoco, 2024-07-21 17:24:19

I was practicing DP through CSES when I got to the Two Sets II problem, wherein I got the confusion on the usage of mod to get the correct answer.

I had read earlier that if we wish to take mod of a summation, we have to take mod of individual elements of the series and then take the mod of summation.

$$$ \text{ans} = ( \sum_{i=1}^{n} (a[i] \% \text{mod})) \% \text{mod} $$$

But here are my two submitted codes:

  1. Accepted: not taking the overall mod on summation.
  2. Wrong Answer: taking the overall mod on summation.

Due to this, I got confused about how we should be taking the mod and, in general, how you tackle such situations. (Right now, I'm looking for a discussion like the one from which I got to know of the binary search method of while (r-l > 1), which I now use, so I can only stress more on the concept of the problem.)

Теги cses_dp, modulus

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский yoco 2024-07-21 20:55:15 1374
en1 Английский yoco 2024-07-21 17:24:19 1053 Initial revision (published)