Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E
题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同;
题解: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的更多相关文章
- 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 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #500 (Div. 2) [based on EJOI]
Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...
- 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++ ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)
A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...
- 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 ...
- (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 ...
- 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. 题解:很显然只有 \( ...
随机推荐
- Django中间件,信号,缓存
中间件 django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. 在django项 ...
- Log Explorer 恢复误删除、更新数据
一.介绍 详细参考:https://blog.csdn.net/jinjazz/article/details/2459692 转自:https://blog.csdn.net/hch27151099 ...
- 并发 错误 java.lang.IllegalMonitorStateException: current thread not owner 分析
public class ThreadTest implements Callable<String> { public String call() throws Exception { ...
- 深度学习:Keras入门(二)之卷积神经网络(CNN)(转)
转自http://www.cnblogs.com/lc1217/p/7324935.html 1.卷积与神经元 1.1 什么是卷积? 简单来说,卷积(或内积)就是一种先把对应位置相乘然后再把结果相加的 ...
- boost之算法
STL里的算法已经很好了,在boost里有几个小的算法 1.BOOST_FOREACH使用方法,定义一个容器里内部类型数据,容器作为参数传递. #include <iostream> #i ...
- make menuconfig 时出现 mixed implicit and normal rules: deprecated syntax
這是 make 的版本問題!不清楚為何要這樣限制? 將此行 config %config: scripts_basic outputmakefile FORCE改成 ...
- python如何实现多线程
一个线程就是一个轻量级进程,多线程能让我们一次执行多个线程. python是多线程语言,其内置有多线程工具包 python中GIL(全局解释器锁)确保一次执行单个线程.一个线程保存GIL并在将其传递给 ...
- 深度学习2--安装opencv3.1
1\opencv的安装参考视频 2\ 以下内容来自:http://blog.csdn.net/l18930738887/article/details/54696148 本人因为被坑过,所以建议各位最 ...
- http://www.uupoop.com/ps/
网页版PS,在线PS 基本的PS功能都有,最重要的一点是快,网页版的嘛,哼哼!
- Hibernate一对多、多对一关联
一对多.多对一关联:在多方加外键 示例:Group(一方)和User(多方),一个Group可以有多个User,每个User只能属于一个Group 多对一单向关联 在User(多方)中建Group ...