[CF1140C]Playlist
Description:
给你n首歌,每首歌有一个长度\(a_i\)和美丽度\(b_i\)
现在可以选出最多k首,动听值为\(\sum a_i*min_{\sum b_i}\)
Hint:
\(n \le 10^5\)
Solution:
只想到了线段树做法,比较麻烦,比赛时没调出来
%%%\(Na_2S_2O_3\)的\(Idea\)
其实就是一个动态维护前k大的过程
我们先把歌曲按\(b_i\)升序排序,分两段处理:
1.从1到k,直接更新答案,同时把对应\(a_i\)扔到小根堆里,维护一个sum表示前k大的和
2.然后每碰到一个\(a_i\),看他是否大于堆顶,大于则替换,否则的话用 它的值+sum-堆顶 来更新答案
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
const int mxn=1e5+5;
int n,m,cnt,hd[mxn];
inline int read() {
char c=getchar(); int x=0,f=1;
while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
while(c<='9'&&c>='0') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
return x*f;
}
inline void chkmax(ll &x,ll y) {if(x<y) x=y;}
inline void chkmin(ll &x,ll y) {if(x>y) x=y;}
struct ed {
int to,nxt;
}t[mxn<<1];
inline void add(int u,int v) {
t[++cnt]=(ed) {v,hd[u]}; hd[u]=cnt;
}
struct G {
int a,b;
}T[mxn];
int cmp(G x,G y) {
return x.b>y.b;
}
priority_queue<int ,vector<int> , greater<int > > q;
ll ans,sum,k;
int main()
{
n=read(); k=read();
for(int i=1;i<=n;++i) {
T[i].a=read(); T[i].b=read();
}
sort(T+1,T+n+1,cmp);
for(int i=1;i<=k;++i) {
sum+=T[i].a; q.push(T[i].a);
chkmax(ans,T[i].b*sum);
}
for(int i=k+1;i<=n;++i) {
if(T[i].a>=q.top()) {
sum-=q.top()-T[i].a;
q.pop(); q.push(T[i].a);
ans=max(1ll*sum*T[i].b,ans);
}
else {
chkmax(ans,(sum-q.top()+T[i].a)*T[i].b);
}
}
printf("%lld",ans);
return 0;
}
[CF1140C]Playlist的更多相关文章
- CF 268E Playlist(贪心)
题目链接: 传送门 Playlist time limit per test:1 second memory limit per test:256 megabytes Description ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- HLS playlist典型示例
[时间:2018-06] [状态:Open] [关键词:流媒体,HLS,m3u8,playlist,variant, alternate] 0 引言 本文主要是对apple官网上的echnical N ...
- vue-music 关于playlist (底部播放列表组件)
建立playlist.vue 组件,在player.vue 组件中引用,点击迷你播放器的播放列表按钮由下至上弹出这个层,所以在player.vue 播放器组件中引用 在playlist.vue 组件中 ...
- ffplay 播放m3u8 hls Failed to open segment of playlist 0
用ffplay 播放m3u8文件 出现 Failed to open segment of playlist 0,Error when loading first segment 'test0.ts' ...
- VLC-FM PLAYLIST
VLC-FM-PLAYLIST.xspf <?xml version="1.0" encoding="UTF-8"?> <playlist x ...
- Codeforces A. Playlist(暴力剪枝)
题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 并不对劲的CF1237D&E:Balanced Playlist and Binary Search Trees
CF1237D Balanced Playlist 题意 有一个长度为\(n\)(\(n\leq 10^5\))的循环播放歌单,每首歌有一个优秀值\(a_i\)(\(a_i\leq 10^9\)). ...
随机推荐
- mui框架中dialog框的实现
<script type="text/javascript" charset="utf-8"> //mui初始化 mui.init({ swipeB ...
- (八)python中的函数
一.聊聊函数 1.什么是函数? 上学时我记得最简单的是 F=x+y 这是一个简单的函数,看看python 中的格式 def test(): #函数定义 def 万年不变 print("> ...
- DC综合简单总结(2)
DC综合简单总结(2) 建立时间和保持时间和数据输出延时时间 一.概念 建立时间和保持时间都是针对触发器的特性说的. 建立时间(Tsu:set up time) 是指在触发器的时钟信号上升沿到来以前, ...
- nodejs的package.json依赖dependencies中 ^ 和 ~ 的区别
nodejs的package.json定义了一个模块,包括其依赖关系的一个简单的JSON文件,该文件可以包含多个不同的指令来告诉Node包管理器如何处理模块. dependencies则表示此模块依赖 ...
- c#串口编程(转)
在单片机项目开发中,上位机也是一个很重要的部分,主要用于数据显示(波形.温度等).用户控制(LED,继电器等),下位机(单片机)与 上位机之间要进行数据通信的两种方式都是基于串口的: USB转串口 — ...
- windows环境下curl 安装和使用
原文:https://blog.csdn.net/qq_21126979/article/details/78690960?locationNum=10&fps=1 一.curl 安装 cur ...
- 获取页面所有a标签href
for(i=0;i<=document.getElementsByTagName("a").length;i++){ console.log(document.getElem ...
- js 字符串切割
对于字符串的切割截取平时所用可能不是特别多,而且分的比较细,所以自备自查.有备无患. 由于之前所有均在一个demo测试,若是哪里打错了,敬请谅解.一些其余属性找时间继续添加. 1.函数:split() ...
- Lesson 1-1
1.1常见难记的几种运算符 1.1.1 除运算 ‘/’ 除运算的结果为小数,即浮点数. >>> 10/3 3.3333333333333335 >>> 10/2 5 ...
- 软件工程作业-(third)
1.选题目(1) 最大连续子数组和(最大子段和) 问题:给定n个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的子段和的最大值. ...