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的更多相关文章

  1. CF 268E Playlist(贪心)

    题目链接: 传送门 Playlist time limit per test:1 second     memory limit per test:256 megabytes Description ...

  2. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  3. 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 ...

  4. HLS playlist典型示例

    [时间:2018-06] [状态:Open] [关键词:流媒体,HLS,m3u8,playlist,variant, alternate] 0 引言 本文主要是对apple官网上的echnical N ...

  5. vue-music 关于playlist (底部播放列表组件)

    建立playlist.vue 组件,在player.vue 组件中引用,点击迷你播放器的播放列表按钮由下至上弹出这个层,所以在player.vue 播放器组件中引用 在playlist.vue 组件中 ...

  6. 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' ...

  7. VLC-FM PLAYLIST

    VLC-FM-PLAYLIST.xspf <?xml version="1.0" encoding="UTF-8"?> <playlist x ...

  8. Codeforces A. Playlist(暴力剪枝)

    题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. 并不对劲的CF1237D&E:Balanced Playlist and Binary Search Trees

    CF1237D Balanced Playlist 题意 有一个长度为\(n\)(\(n\leq 10^5\))的循环播放歌单,每首歌有一个优秀值\(a_i\)(\(a_i\leq 10^9\)). ...

随机推荐

  1. Virtualbox Ubuntu 虚拟机命令行挂载共享文件夹及设置静态IP

    挂载共享文件夹 参考 [1], VirtualBox/GuestAdditions [2], VirtualBox/SharedFolders 步骤 在Virtualbox 虚拟机的菜单『设备』中,点 ...

  2. 第十七节,OpenCV(学习六)图像轮廓检测

    1.检测轮廓 轮廓检测是图像处理中经常用到的,OpenCV-Python接口中使用cv2.findContours()函数查找检测物体的轮廓. cv2.findContours(image, mode ...

  3. c++ Qt向PHP接口POST文件流

    Qt调用PHP写的接口,向其传递图片文件,并保存在服务器. 二进制文件无法直接传递,Qt采用Base64进行编码发送,PHP解码保存为文件. 注意:PHP收到数据之后会将POST过来的数据中的加号(+ ...

  4. pointer-events属性屏蔽鼠标事件(点击穿透上层元素)

    应用场景 我们在 HTML 开发时可能会遇到这样的情况:页面上有一些元素使用绝对定位布局,这些元素可能会遮盖住它们位置下方的某个元素的部分或者全部.默认情况下,下方元素被遮挡的部分是不会响应鼠标事件的 ...

  5. MailKit系列之附件分离

    本文主要谈谈实现思路,不提供完整代码 一.分离基础 1.MIME邮件的multipart类型 引用文章:https://blog.csdn.net/wangyu13476969128/article/ ...

  6. vs/windows程序找不到入口点cuvidGetDecodeStatus于AppDecGL.exe动态链接库上

    解决方法:这个问题的原因是由于使用的英伟达显卡驱动版本不够新,更新显卡驱动即可. 找了一个多月的原因,终于知道起源了.最终问题还是出在了nvcuvid.lib/.dll上面.通过分析vs调试信息可以得 ...

  7. boostrap日期时间插件datetimepicker使用过程的一些问题总结

    1.汉化问题 虽然有转门的汉化脚本,不过如果简单使用的话自己稍微改一下源码就行了: var dates = $.fn.datetimepicker.dates = { en: { days: ['Su ...

  8. linux文件删除原理

    文件删除的原理 linux的文件名是存在父目录的block里面的,并指向这个文件的inode节点,这个文件的inode节点在标记指向存放这个文件的block的数据块.我们删除文件,实际上不是清除ino ...

  9. Springboot 打jar包分离lib,配置文件正确方式

    文章来源:https://my.oschina.net/xiaozhutefannao/blog/1932764 POM.xml <?xml version="1.0" en ...

  10. 函数式编程-compose与pipe

    函数式编程中有一种模式是通过组合多个函数的功能来实现一个组合函数.一般支持函数式编程的工具库都实现了这种模式,这种模式一般被称作compose与pipe.以函数式著称的Ramda工具库为例. cons ...