[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\)). ...
随机推荐
- windows 双网卡同时上专网(内网)和外网
本操作是用网线做专网(内网),无线网卡用于外网 1. 记录有线网卡的网络的网关,例如10.103.14.1 2. 有线网卡必须是手动指定的ip地址,把网关清掉,例如 3. 删除0.0.0.0 路由 r ...
- 使用第三方工具Thumbnailator动态改变图片尺寸
Thumbnailator项目git地址:https://github.com/coobird/thumbnailator 使用步骤 1.添加依赖 <!-- Thumbnailator图片处理 ...
- spring cloud分布式配置中心案例
这里仍然以Windows.jdk和idea为开发环境,按照下面的步骤打包-运行-访问就能看到效果:启动注册中心:java -jar F:\jars-config\register-0.0.1-SNAP ...
- Qt+mpg123+openal播放MP3流
#ifndef PLAYSTREAM_H #define PLAYSTREAM_H #include <QObject> #include "../libMPG123/mpg12 ...
- 初识C语言(二)
C语言标识符的命名规则 变量或者函数起的名字就是标识符,而且C语言的标识符有它自己的命名规则: 标识符的长度最好不要超过8位,因为在一些版本的C语言中标示符的前八位是有效的,所以当两个标识符的前八位相 ...
- python2 使用pip安装psycopg2出现错误:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-mvzdNj/psycopg2/
公司业务需求,开发语言python2,需要使用数据库:postgresql,需要安装模块psycopg2这个模块, 使用pip install psycopg2 报错: Command "p ...
- 04-HTTP协议和静态Web服务器
一.HTTP协议(HyperText Transfer Protocol) 超文本传输协议,超文本是超级文本的缩写,是指超越文本限制或者超链接,比如:图片.音乐.视频.超链接等等都属于超文本. ...
- 马拉车算法——边界拓展时加限制hdu4513
#include<bits/stdc++.h> using namespace std; #define maxn 500005 int n,p[maxn],s[maxn],s_new[m ...
- php 常用的知识点归集(上)
1.php if...else 在html中的替代语法 <?php $name = 'ok' ?> <?php if ($name == '1ok') : ?> <div ...
- 图的最小环floyed
最优的路线 问题描述 学校里面有N个景点.两个景点之间可能直接有道路相连,用Dist[I,J]表示它的长度:否则它们之间没有直接的道路相连.这里所说的道路是没有规定方向的,也就是说,如果从I到J有直接 ...