Please read the new rule regarding the restriction on the use of AI tools. ×

Maximum sum alternating subsequence question

Revision en1, by AkeenL, 2021-04-12 01:20:50

I was doing https://codeforces.me/contest/1420/problem/C1 which is a max sum alternating subsequence problem. I understand the dp solution but I fail to understand why adding the first number in the array then adding every positive arr[i] — arr[i-1] works if you have to choose numbers starting from the first element.

Tags #implementation, #greedy

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English AkeenL 2021-04-12 01:20:50 373 Initial revision (published)