题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同;

题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相减,然后直到找不到为止,

但是这样的时间复杂度是O(N^2),想了很久还是不知道怎么用优先队列来优化= =,结果发现别人都不是这个规律做的。。。。,都是直接暴力扔进去,直接减,为了保证减的是最大的,把减过后的数仍两个到队列里,这样保证了再次减的时候相当于,当前数减了之前那个数,而且把中间数扔进了队列

#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define read(a) scanf("%d",&a)
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; priority_queue<int,vector<int>,greater<int> >q;
int main()
{
int n;
read(n);
ll ans=;
for(int i=;i<n;i++)
{
int a;
read(a);
if(q.empty()||a<=q.top())q.push(a);
else
{
ans+=a-q.top();
q.pop();
q.push(a);
q.push(a);
}
}
printf("%lld\n",ans);
return ;
}
/******************** ********************/

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E的更多相关文章

  1. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)

    Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  3. Codeforces Round #500 (Div. 2) [based on EJOI]

    Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...

  4. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  5. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  6. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

    A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...

  7. Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937

    https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...

  8. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

    A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \( ...

随机推荐

  1. 使用QFile进行文件操作(QFile可以使用FILE *指针,还必须指定AutoCloseHandle)

    QFile类我我们提供了操作文件的常用功能.它是一种io设备,可以用来读写文本文件和二进制文件,也可以用来读写Qt的资源文件.QFile类可以单独使用,该类本身提供了read/write函数,但更方便 ...

  2. MySQL中lock与latch的区分

    这里要区分锁中容易令人混淆的概念lock与latch.在数据库中,lock与latch都可以成为锁,但两者有截然不同的含义 latch 一般称为闩锁(轻量级的锁) 因为其要求锁定的时间非常短,若迟勋时 ...

  3. MySQL优化器不使用索引的情况

    优化器选择不适用索引的情况 有时候,有乎其并没有选择索引而去查找数据,而是通过扫描聚集索引,也就是直接进行全表的扫描来得到数据.这种情况多发生于范围查找.JOIN链接操作等情况.例如 ; 通过SHOW ...

  4. Linux中vim命令出现E325错误解决方法

    出现该问题的原因是: vim在编辑文件的时候会创建一个swp file来保证文件的安全性,如果没有正常退出vim的,下次打开这个文件就会报E325的错误,提示swp文件已经存在. 解决方法也简单:把这 ...

  5. JavaScript+css+ div HTML遮罩層效果

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title ...

  6. SDWebImage浅析

    第一部分 SDWebImage库的作用: 通过对UIImageView的类别扩展来实现异步加载替换图片的工作. 主要用到的对象: 1)UIImageView(WebCache)类别,入口封装,实现读取 ...

  7. hadoop linux 杂记

    切换到root        su    修改sudo sudo + 命令 --> root权限 + 命令        su root        vim /etc/sudoers      ...

  8. ajax json 异步请求

    function ajaxTest(){ if (true) { $.ajaxSettings.async = false; var dataJson; $.getJSON("/univer ...

  9. Loadrunder脚本篇——Running Time setting之Additional attributes

    作用说明 为Vuser脚本提供额外自定义参数.额外参数设置可应用于所有Vuser脚本类型. 说明: Add:添加一个参数 Remove:移除一个参数 可以在这里先输入一些常用的参数名及对应的值,类似常 ...

  10. 容器排序之sort,stable_sort

    bool isShorter(const string &s1, const string &sz){ return s1.size() < sz.size(); } int m ...