#include using namespace std; using ll = long long; const int INF = 1e9; const int high = 1e4+1; int main() { int n; cin >> n; vector a(n); for(int i = 0; i < n; i++)cin >> a[i]; vector> dp(n + 1, vector(high, INF)); //dp[i][j] := a[i]の段差j以下に行くときの最小コスト for(int i = 0; i < high; i++)dp[0][i] = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < high; j++) { dp[i + 1][j] = min(dp[i + 1][j], abs(a[i] - j) + dp[i][j]); if(j != 0)dp[i + 1][j] = min(dp[i + 1][j - 1], dp[i + 1][j]); } } cout << dp[n][high-1] << endl; }