Tên đăng nhập Điểm ▾ Bài tập Giới thiệu
27901 50 1
27901 50 1

include <iostream>

include <vector>

using namespace std;

int main() {
int n;
cin >> n;

vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}

vector<vector\<int>> f(n + 1, vector<int>(max(a) + 1));

for (int i = 0; i <= n; i++) {
for (int j = 0; j <= max(a); j++) {
if (i == 0) {
f[i][j] = 0;
} else {
f[i][j] = min(
f[i - 1][j],
f[i - 1][j - 1] + (j - a[i - 1]),
f[i - 1][j + 1] + (a[i - 1] - j)
);
}
}
}

cout << f[n][a[n - 1]] << endl;

return 0;
}

27901 50 1
27901 50 1
27901 50 1

uwu

27901 50 1
27901 50 1
27901 50 1
27901 50 1
27901 50 1

siu

27901 50 1
27901 50 1
27901 50 1
27914 48 2
27915 48 1
27915 48 1
27915 48 1
27918 47 2
27919 46 1
27920
buihoangminh
Bùi Hoàng Minh
46 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920 45 1
27920
mttn100nc
NC NT Tran Van Nhan
45 2
27920 44 2
27932 44 1
27932
mttn050cb
CB DNo Nguyen Minh Hoang
44 1
27934 43 1
27935 43 1
27936 42 2
27937
mttn118cb
CB CT Tran Minh Phuoc
42 3
27938 42 1
27939 41 1
27940
mttn040nc
NC LD-CTL Vo Dinh Cao Minh Hao
41 3
27941 41 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942
A_019
PHAM MINH HAI
40 1
27942
A_047
TRAN BA KHOA
40 1
27942
A_051
NGUYEN HUU TUAN KHOA
40 1
27942
A_078
PHUNG HOANG QUAN
40 1
27942
A_146
NGUYEN KHANG
40 1
27942
A_157
TRAN NGOC HUNG
40 1
27942
A_162
NGUYEN CONG QUY
40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1

:DD

27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942
famvandao
khuekids
40 1

thi tin học trẻ 2024

27942 40 1
27942 40 1
27942 40 1
27942 40 1
27942 40 1

cac

27942 40 1
27942 39 2
27942 39 2
27942
mttn158cb
CB KT Nguyen Phu Trong
39 3
27992
mttn036cb
CB BDi-LQD Le Vo Hoang Ha
38 3
27993 38 1
27994
mttn063nc
NC QNg Nguyen Pham Gia Huy
37 3
27995
mttn068cb
CB DT-NQD Nguyen Tan Kiet
37 3
27996 36 1
27997 36 1
27998 35 1
27998 35 1
28000 33 1