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. rem是怎么计算的(转载)

    「rem」是指根元素(root element,html)的字体大小,从遥远的 IE6 到版本到 Chrome 他们都约好了,根元素默认的 font-size 都是 16px. rem是通过根元素进行 ...

  2. 利用request和re抓取猫眼电影排行

    import requests import re import time def get_one_page(url): headers = { 'User-Agent': 'Mozilla/5.0 ...

  3. RE模块垃圾回收机制

    今日内容 一.垃圾回收机制 函义:不能被程序访问到的数据,就称之为垃圾 1.引用计数 引用计数是用来记录值的内存地址被记录的次数的  每一次对值地址的引用都可以使该值的引用计数 +1 每一次对值地址的 ...

  4. 小E浅谈丨区块链治理真的是一个设计问题吗?

    在2018年6月28日Zcon0论坛上,“区块链治理”这个话题掀起了大神们对未来区块链治理和区块链发展的一系列的畅想. (从左至右,分别为:Valkenburgh,Zooko,Jill, Vitali ...

  5. 将Chrome插件Momentum背景图片设为桌面壁纸

    Momentum简介 Momentum插件是一款自动更换壁纸,自带时钟,任务日历和工作清单的chrome浏览器插件.官方的解释就是:替换你 Chrome 浏览器默认的“标签页”.里面的图片全部来自50 ...

  6. python&django 实现页面中关联查询小功能(基础篇)

    效果 实现效果图如下,根据过滤条件查询相关信息. 知识点 1.配置URL,在路由中使用正则表达式 2.过滤查询 代码 setting.py from django.contrib import adm ...

  7. apache无法启动报错No space left on device

    apache无法启动报错No space left on device 故障现象:apache无法启动ipcs信号量很多 # service httpd startStarting httpd : [ ...

  8. mysql 5.7版本后时间datetime 默认为 0000-00-00 00:00:00 问题

    CREATE TABLE `test_user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` char(25) DEFAULT '' ...

  9. 《剑指offer》翻转单词顺序列

    本题来自<剑指offer> 反转链表 题目: 思路: C++ Code: Python Code: 总结:

  10. Map,HashMap,LinkedHashMap,TreeMap比较和理解

    /* * 获取功能: * V get(Object key):根据键获取值 * Set<K> keySet():获取集合中所有键的集合 * Collection<V> valu ...