Imagine a person takes a walk through some hilly territory, and they record their elevation at intervals as they go.
How would you calculate their total ascent, given that there is some error in the data? Your algorithm should count ascent gain when they walk up a hill, but probably not if they undulate up and down a bit on the path or due to GPS error.
If you count every foot of elevation gain, then you will end up with an unrealistically large ascent.