SutSun @ 2024-11-29 19:54:40
题目传送门
只有Subtask #1 WA了, AC了但是又没有完全AC
蒟蒻代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
set<int> a;
int n;
long long s=0;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
auto t=a.lower_bound(x);
if(i==1) s+=abs(x);
else{
auto r=t;
r--;
if(t==a.end()) s+=abs(*r-x);
else if(t==a.begin()) s+=abs(*t-x);
else s+=min(abs(*t-x),abs(*r-x));
}
a. insert(x);
}
cout<<s;
return 0;
}
求调,玄关 orz