Code:
#include<cstdio> using namespace std; int main() { int last=0,ans=0; int n;scanf("%d",&n); for(int i=1;i<=n;++i) { int t;scanf("%d",&t); if(t>last)ans+=t-last; last=t; } printf("%d ",ans); }