Music in Car CodeForces - 746F (贪心,模拟)
大意: n首歌, 第$i$首歌时间$t_i$, 播放完获得贡献$a_i$, 最多播放k分钟, 可以任选一首歌开始按顺序播放, 最多选w首歌半曲播放(花费时间上取整), 求贡献最大值.
挺简单的一个题, 实现的时候还是漏了好多细节. 具体思路就是滑动区间, 维护区间内可以减少的前w大时间, 要注意w大以后的要扔进另一个队列, 滑动的时候若不足w的时候用另一个队列补充.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 1e6+10;
int n, w, k;
int a[N], t[N];
pii r[N];
set<pii> s;
set<pii,greater<pii> > res; int main() {
scanf("%d%d%d", &n, &w, &k);
REP(i,1,n) scanf("%d", a+i);
REP(i,1,n) scanf("%d", t+i), r[i]=pii(t[i]/2,i);
int now = 1, c = 0, p = 0, ans = 0;
REP(i,1,n) {
while (now<=n&&c<k) {
c += t[now]-r[now].x;
p += a[now];
s.insert(r[now]);
if (s.size()==w+1) {
c += s.begin()->x;
res.insert(*s.begin());
s.erase(s.begin());
}
if (c<=k) ans = max(ans, p);
++now;
}
if (res.count(r[i])) res.erase(r[i]);
if (s.count(r[i])) {
s.erase(r[i]), c -= t[i]-r[i].x;
if (res.size()) {
c -= res.begin()->x;
s.insert(*res.begin()), res.erase(res.begin());
}
}
else c -= t[i];
p -= a[i];
if (c<=k) ans = max(ans, p);
}
printf("%d\n", ans);
}
Music in Car CodeForces - 746F (贪心,模拟)的更多相关文章
- CodeForces - 730A 贪心+模拟
贪心策略: 1.只有一个最大值,选着第二大的一起参加比赛减分. 2.有奇数个最大值,选择三个进行比赛. 3.偶数个最大值,选择两个进行比赛. 为什么不把最大值全部选择? 因为最多只能选五个,有可能选择 ...
- Population Size CodeForces - 416D (贪心,模拟)
大意: 给定$n$元素序列$a$, 求将$a$划分为连续的等差数列, 且划分数尽量小. $a$中的$-1$表示可以替换为任意正整数, 等差数列中必须也都是正整数. 贪心策略就是从前到后尽量添进一个等差 ...
- Arthur and Questions CodeForces - 518E (贪心模拟)
大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简 ...
- Codeforces 1042C (贪心+模拟)
题面 传送门 分析 思路简单,但代码较复杂的贪心 分类讨论: 有0 负数有奇数个:将绝对值最小(实际最大)的负数和0全部乘到一起,最后删掉0 负数有偶数个:将0全部乘到一起,最后删掉0 没有0 负数有 ...
- Sums of Digits CodeForces - 509C (贪心,模拟)
大意: 一个未知严格递增数组$a$, 给定每个数的数位和, 求$a[n]$最小的数组$a$ #include <iostream> #include <algorithm> # ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- CodeForces ---596B--Wilbur and Array(贪心模拟)
Wilbur and Array Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Su ...
- Music in Car CodeForces - 746F
Music in Car CodeForces - 746F 题意很难懂啊... 题意:http://blog.csdn.net/a838502647/article/details/74831793 ...
- 贪心+模拟 ZOJ 3829 Known Notation
题目传送门 /* 题意:一串字符串,问要最少操作数使得成为合法的后缀表达式 贪心+模拟:数字个数 >= *个数+1 所以若数字少了先补上在前面,然后把不合法的*和最后的数字交换,记录次数 岛娘的 ...
随机推荐
- CentOS7 时间设置与网络同步
1.查看时区 [root@localhost /]# date -R Thu, Jul :: + +0800表示东八区,这边就不用再设置 时区中的CST表示中国标准时间. 时区相关共享文件在/usr/ ...
- X-Pack for the Elastic Stack [6.2] » Securing the Elastic Stack »Setting Up User Authentication
https://www.elastic.co/guide/en/x-pack/current/setting-up-authentication.html Active Directory User ...
- 通过cmd调用Powershell脚本
一共需要3个文件,把这3个文件放在一个路径下 UTF8NoBOM.bat 这个文件是为了调用ps1 pwsh -file "%cd%\UTF8NoBOM.ps1" UTF8No ...
- 比较好的一些 ConcurrentHashMap讲解博客
jdk8 https://blog.csdn.net/jianghuxiaojin/article/details/52006118#commentBox jdk7.8 https://crossov ...
- 题解——洛谷P2827 NOIP提高组 2016 蚯蚓
队列模拟 详细题解待填坑 #include <cstdio> #include <algorithm> #include <queue> #include < ...
- Ubuntu14.04下 升级 cmake
参考: How to install cmake 3.2 on ubuntu 14.04? Ubuntu14.04下升级cmake 1.通过PPA安装: $ sudo apt-get install ...
- 【译】第5节---Code First约定
原文:http://www.entityframeworktutorial.net/code-first/code-first-conventions.aspx 我们在上一节中已经看到了EF Code ...
- 最简单的服务器和客户机(python3的编码与解码问题)
在学习python的过程中,我越来越感觉到python2和python3之间有很多不同点,最近发现的一点就是编码问题. 在代码清单14-1和14-2中,因为作者是用python2来写得,然后我是用py ...
- 使用 jenkins 搭建CI/CD流水线 (MAC)
如何搭建持续集成/持续交付平台?? 如何使用jenkins搭建持续交付流水线,以及和其他工具(如artifactory)集成?如何使用元数据,记录软件发布过程的构建信息,测试结果,并用rest Api ...
- border:none和border:0的区别
C:当定义border:none时,表示无边框样式,浏览器并不会对边框进行渲染,也就没有实际的宽度: D:定义边框时,除了设置宽度外,还必须设置边框的样式才能显示出来. border:0;浏 ...