262B - Roma and Changing Signs 3125661 this is the problem and my submission please, i want to know why it is WA. thank you :)
# | User | Rating |
---|---|---|
1 | ecnerwala | 3649 |
2 | Benq | 3581 |
3 | jiangly | 3578 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | tourist | 3565 |
8 | maroonrk | 3531 |
9 | Radewoosh | 3521 |
10 | Um_nik | 3482 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 161 |
4 | TheScrasse | 159 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | SecondThread | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
262B - Roma and Changing Signs 3125661 this is the problem and my submission please, i want to know why it is WA. thank you :)
Name |
---|
If your program gives a wrong answer on the first sample test, you'd better think of a better solution because this must be a completely wrong algorithm.
By the way, I do realize why you obfuscate your code, but for the start you'd better work on the algorithm, not worry about what happens after you send the code.
Your algorithm has several errors.
First, in the case where K < N, you do this...
And in the end, you have this...
So you'll end up summing only numbers in the range K+1..N. The correct thing to do, is to do something similar to what you do when K >= N (you change the signs of all negative numbers and count how many changes you've made).
Then, another error is that you have the sort and the check whether (K — c) % 2 != 0 inside the K >= N case, and that check must always be made, not only when K >= N. Consider the following test case...
K = 4 and N = 6, and you still have to make one additional sign change after changing the signs of all negative numbers.
I made those modifications to your code and it got AC. Here it is -> 3132417