标签:lap algo 黑科技 get clu clear png led href

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 0x7FFFFFFF
#define ll long long
void read(int &x){
x=0;int f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
x*=f;
}
set<int>tree;
int n,x,ans,add;
int main(){
read(n);tree.clear();read(x);ans=x;tree.insert(x);
for(int i=2;i<=n;i++){
read(x);add=INF;
set<int>::iterator a=--tree.lower_bound(x),b=tree.lower_bound(x);
if(tree.count(*a)) add=min(add,abs(x-*a));
if(tree.count(*b)) add=min(add,abs(x-*b));
//printf("%d %d\n",*a,*b);
ans+=add;
tree.insert(x);
}
printf("%d\n",ans);
return 0;
}
标签:lap algo 黑科技 get clu clear png led href
原文地址:http://www.cnblogs.com/ZincSabian/p/7582038.html