luogu_1969 积木大赛
#include <cstdio> #include <iostream> using namespace std; int n,a[100010],ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]>a[i-1])ans+=a[i]-a[i-1]; } printf("%d\n",ans); return 0; }
#include <cstdio> #include <iostream> using namespace std; int n,a[100010],ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); if(a[i]>a[i-1])ans+=a[i]-a[i-1]; } printf("%d\n",ans); return 0; }