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

题解: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. SpringBoot + Thymeleaf + Validate验证

    在开发业务时,不可避免的需要处理一些校验, 如果是写 if-else 这种代码去校验, 那会有一大段这样的代码.不过还好有个校验插件: javax.validation.validation-api  ...

  2. Linux下安装MongoDB全程记录

    1.下载安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.0.tgz 2.解压缩 [root@loca ...

  3. ThreadPoolExecutor 线程池任务队列分析 与 利特尔法则(Little's law)

    一. 演示 public class ThreadPoolTest { static class MyThread implements Runnable { private String name; ...

  4. DOM 属性操作

    1 属性节点 2 attribute操作 3 value获取值操作 4 class的操作 5 指定CSS操作 1.属性节点 //获取文本节点的值 var divEle = document.getEl ...

  5. 《Python 数据分析》笔记——数据的检索、加工与存储

    数据的检索.加工与存储 1.利用Numpy和pandas对CSV文件进行写操作 对CSV文件进行写操作,numpy的savetxt()函数是与loadtxt()相对应的一个函数,他能以诸如CSV之类的 ...

  6. ABAP 断点篇-001

    断点技能不足! 6.2.4 可在调试画面设置break-point.方法:在代码前面双击 6.2.5 为指定语句设置断点方法:(1)选择菜单:Breakpoints->Breakpointat ...

  7. 【转】Python爬虫_示例

    爬虫项目:爬取汽车之家新闻资讯   # requests+Beautifulsoup爬取汽车之家新闻 import requests from bs4 import BeautifulSoup res ...

  8. Tensorflow学习笔记(1)--安装

    安装 1.ubuntu 14.04 2. 清华大学开源软件镜像站:https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/ (要求sudo权限,如果报 ...

  9. 设计模式之单例模式--instance

    <?php header('Content-Type:text/html;charest=utf-8'); /** * 设计模式之单例模式 * $_instance必须声明为静态的私有变量 * ...

  10. Loadrunder常见问题汇总(持续更新)

    1.LR 脚本为空的解决方法: 1)如果安装了IE以外的浏览器,并且IE不是默认浏览器,则无法生成录制脚本 2)如果录制脚本时IE不能打开,则需要将浏览器的IE工具高级选项中,将“启用第三方浏览器扩展 ...