#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; VI Y(N); REP(i, N)cin >> Y[i]; int ans = LLINF; eREP(i, 10000) { int now = 0; int cnt = 0; REP(j, N) { if (now <= Y[j]) { if (Y[j] <= i) { now = Y[j]; } else { now = i; cnt += (Y[j] - i); } } else { //now = Y[j]; cnt += (now - Y[j]); } } //if (i < 10)cout << cnt << " " << i << endl; chmin(ans, cnt); } cout << ans << endl; return 0; }