[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\)). ...
随机推荐
- list不是模板
vector和list在命名空间std里,还需要添加声明 using namespace std;
- git错误记录及解决
一.git每次提交.拉取都要输用户名和密码 问题描述:每次提交.拉取文件时都要输用户名和密码,特别麻烦 原因:在git上面注册了用户名a,然后本机安装了TortoiseGit工具,登录时会在本机C:\ ...
- 「IOI2018」狼人
快咕一个月了 咕咕咕 咕咕咕咕 LOJ #2865 Luogu P4899(离线) UOJ #407(强制在线) 题意 给定一棵树和若干组询问$(S,E,L,R)$ 表示你初始在$S$,想到达$E$, ...
- day 19 - 1 模块
collections 模块 在内置数据类型(dict.list.set.tuple)的基础上,collections 模块还提供了几个额外的数据类型:Counter.deque.defaultdic ...
- Vue-计算属性和侦听属性
复杂逻辑应使用计算属性而不应写在插值表达式{{ }}里 <div id="app"> 原值:{{ msg }} <br> 翻转后的值:{{ reverseM ...
- Java基础14-缓冲区字节流;File类
作业解析 阐述BufferedReader和BufferedWriter的工作原理, 是否缓冲区读写器的性能恒大于非缓冲区读写器的性能,为什么,请举例说明? 答: BufferedReader对Rea ...
- Django_路由详
动态路由和动态参数捕获 动态路由:url支持正则表达式, 访问的url能够匹配成功就去执行对应的视图函数 捕获参数: # 捕获参数,位置传参 url(r'^data/([0-9]{4})/([0-2] ...
- 【转】Beginning Game Programming v2.0
Beginning Game Programming v2.0 Last Updated 8/19/18 Greetings everyone, welcome to the ground up re ...
- 各种手工DIY
http://www.guokr.com/scientific/subject/diy/ 高仿宜家莲花灯 http://www.guokr.com/article/179863/ 做一只会发光的魔幻吊 ...
- Light OJ 1266 - Points in Rectangle
题目 Link 就是查询矩形内有多少个点. 分析 二维树状数组维护就好了,. Code #include <bits/stdc++.h> const int maxn = 1000 + 1 ...