mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 21:16:27 +00:00
P2234 [HNOI2002]营业额统计
R44585310
This commit is contained in:
parent
105979fd16
commit
8859e00f07
25
Luogu/problem/P2234/P2234.cpp
Normal file
25
Luogu/problem/P2234/P2234.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, x, sum = 0;
|
||||
vector<int> a;
|
||||
cin >> n >> x;
|
||||
a.push_back(0xc0c0c0c1);
|
||||
a.push_back(x);
|
||||
sum += x;
|
||||
for (int i = 2; i <= n; i++) {
|
||||
cin >> x;
|
||||
int t1 = *--lower_bound(a.begin(), a.end(), x);
|
||||
int t2 = *lower_bound(a.begin(), a.end(), x);
|
||||
if (t1 == -0x3f3f3f3f) {
|
||||
sum += abs(t2 - x);
|
||||
} else {
|
||||
sum += min(abs(t1 - x), abs(t2 - x));
|
||||
}
|
||||
a.insert(upper_bound(a.begin(), a.end(), x), x);
|
||||
}
|
||||
cout << sum << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user