← 返回题目页

A1425 [2013 S4] 积木大赛

标程

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    long long ans = 0;
    long long prev = 0;
    for (int i = 0; i < n; i++) {
        long long h;
        cin >> h;
        if (h > prev) ans += h - prev;
        prev = h;
    }
    cout << ans << "\n";
    return 0;
}

动画演示