You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
587 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 32768;
const int INF = 0x3f3f3f3f;
int a[N];
int n;
//10个测试点过了3个得30分7个测试点TLE
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int sum = a[1];
for (int i = 2; i <= n; i++) {
//每一个都向前找,找出差的绝对值最小的数
int minX = INF;
for (int j = i - 1; j >= 1; j--)
if (abs(a[j] - a[i]) < minX) minX = abs(a[j] - a[i]);
sum += minX;
}
cout << sum << endl;
return 0;
}