| 记录编号 | 248755 | 评测结果 | AAAAAAAAAA | 
    
        | 题目名称 | 1533.[HNOI 2002]营业额统计 | 最终得分 | 100 | 
    
        | 用户昵称 |  asddddd | 是否通过 | 通过 | 
    
        | 代码语言 | C++ | 运行时间 | 0.091 s | 
    
        | 提交时间 | 2016-04-11 11:24:21 | 内存使用 | 0.28 MiB | 
    
    
    
    		显示代码纯文本
		
		#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
#define inf 999999999
using namespace std;
set<int>haha;
int main(){
    freopen("turnover.in","r",stdin);
    freopen("turnover.out","w",stdout);
    ios::sync_with_stdio(0);
    haha.insert(inf);
    haha.insert(-inf);
    int ans=0;
    int n;
    cin>>n;
    int x;
    cin>>x;
    haha.insert(x);
    ans+=x;
    for (int i=1; i<n; i++) {
        if (!(cin>>x)) {
            x=0;
        }
        ans+=min(*haha.lower_bound(x)-x,x-*(--haha.lower_bound(x)));
        haha.insert(x);
    }
    cout<<ans;
}