#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; ll dp[1005][1005]; ll sdp[1005][1005]; void solve() { int n; scanf("%d", &n); vector a(n); int i, j; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i <= n; i++) { for (j = 0; j <= 1000; j++) { dp[i][j] = LINF; } } for (j = 0; j <= 1000; j++) { dp[0][j] = abs(j - a[0]); if (j > 0) sdp[0][j] = MIN(sdp[0][j - 1], dp[0][j]); else sdp[0][j] = dp[0][j]; } for (i = 1; i < n; i++) { for (j = 0; j <= 1000; j++) { dp[i][j] = sdp[i - 1][j] + abs(j - a[i]); if (j > 0) sdp[i][j] = MIN(sdp[i][j - 1], dp[i][j]); else sdp[i][j] = dp[i][j]; } } printf("%lld\n", sdp[n - 1][1000]); return; } int main(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t