RedDragon's blog

By RedDragon, history, 4 years ago, In English

This is my submission for problem D in CodeForces Educational Round 90 : 85049220 I used a maximum subarray approach. I took the difference between odd and even parity consecutive elements (gain in sum per pair) and stored them in a new array. After that I used maximum subarray on my new array and added that to sum of even numbers(initially). Pairs can be formed in two ways (0-1, 2-3, 4-5,... & 1-2, 3-4, 5-6,...); took care of that in two cases. Max subarray sum can be negative; took care of that too.

As you can see, the submission got WA in test case 3. And the test case is too big for me to understand the error. Can someone help in pointing out the mistake? Or give a small test case where my code would give a wrong answer?

Thanks in advance!

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Why are you converting ad to int32? I think that's causing problem.

use this line-- cout<<sum+max(0*1ll,ad)<<'\n';

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks! Its working. The thing is, it was becoming incompatible earlier. I typecast-ed ad to int32 instead of 0 to int64_t. My bad