Files
python/TangDou/LuoGuBook/P2234.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
587 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}