Problem 363B - Fence Please tell me why my code doesnt work on the test 17. My submission: 57947524? Thanks)
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Problem 363B - Fence Please tell me why my code doesnt work on the test 17. My submission: 57947524? Thanks)
Name |
---|
I guess you've written a wrong dp. Let's take a look:
$$$dp_i$$$ is the minimum of: 1)sum for an interval $$$[i...i+k-1]$$$ or 2)minimum of dp on interval $$$[1...i-1]$$$
In the case when $$$dp_i$$$ is not sum of $$$[i...i+k-1]$$$, you calc $$$dp_{i+1}$$$ wrong because you you suppose that $$$dp_i$$$ is the sum when substract $$$arr_{i-1}$$$ and add $$$arr_{i+k-1}$$$ to $$$dp_i$$$
What should you do to solve this problem? For example you can just calc $$$dp_i$$$ as the sum of some interval and then iterate over it choosing the one with a minimal sum.
Also you can use a prefix sum method(search in internet, if interested). It solves this problem quite easy.