用set存下就好了。

/**************************************************************
Problem: 1588
User: BLADEVIL
Language: C++
Result: Accepted
Time:180 ms
Memory:1468 kb
****************************************************************/ //By BLADEVIL
#include <cstdio>
#include <set>
#define inf 1<<30 using namespace std; int n,ans; int main()
{
int x;
set<int>bt;
bt.insert(inf); bt.insert(-inf);
scanf("%d",&n);
for (int i=;i<=n;i++)
{
//printf(" %d\n",ans);
if (scanf("%d",&x)==EOF) x=;
if (i==) ans=x,bt.insert(x); else
{
int a,b;
a=*bt.upper_bound(x); b=*(--bt.upper_bound(x));
ans+=(a-x<x-b)?a-x:x-b;
bt.insert(x);
}
}
printf("%d\n",ans);
return ;
}

最新文章

  1. [LeetCode] Ugly Number II 丑陋数之二
  2. java归并排序,单线程vs多线程
  3. Objective—C基础学习总结
  4. CSS3 选择器——伪类选择器
  5. Some settings of PostgreSQL
  6. EasyUI-在iframe里获取现阶段选中的tab的标题
  7. oc-04-类的声明和实现
  8. PHP验证码的制作
  9. Project Euler:Problem 55 Lychrel numbers
  10. linux下virtualenv的python版本
  11. CF# 260 A. Laptops
  12. Linux删除其他程序正在使用的文件
  13. mshadow的原理--MXNet
  14. pandas,pd.ExcelWriter保存结果到已存在的excel文件中
  15. 「POJ - 1003」Hangover
  16. Backbone 学习总结
  17. Eclipse 插件开发 -- 深入理解菜单(Menu)功能及其扩展点( FROM IBM)
  18. 数据加密之RijndaelManaged加密
  19. SQL Server T—SQL 语句【建 增 删 改】(建外键)
  20. mfc Unicode转 ASNI ,WCHAR 转 CHAR

热门文章

  1. 原生javascript自定义input[type=radio]效果
  2. WITH REPLACE 含义
  3. WriteLine(ls.ToString());Console.WriteLine(ls);输出结果相同,为什么要加 .ToString()
  4. window service 创建
  5. javascript中检测一个变量的类型
  6. Socket_SSH-2(大文件的一次传输)
  7. JS详细图解全方位解读this
  8. A表数据插入到B表(表结构不一致)
  9. 「CodePlus 2017 12 月赛」白金元首与独舞
  10. Spring boot——构建rest风格