Why do I get the "division by zero" error in this? https://codeforces.net/contest/1183/submission/56306470 I will be more than appreciated if you help me!
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Why do I get the "division by zero" error in this? https://codeforces.net/contest/1183/submission/56306470 I will be more than appreciated if you help me!
Algorithm: reverse all the positives; if(product is negative) reverse the smallest one.
Proof:
With step1, we got the ABS of the product the greatest.
After step 1, we got the product:
1)positive: No step2. We are done.
2)negative: suppose the product after step 1 is (-1000)*(-2)*k(k<0) .Either we choose (-1000)*1*k, or 999*(-2)*k;
In general, a*(a+b)*k(b,k<0). 1st choice:(-a-1)*(a+b)*k; 2st choice a*(-a-b-1)*k. To make a comparision:((-a^2-a-ab-b)-(-a^2-ab-a))*k=-b*k<0, so we choose to reverse the smallest one.
Name |
---|