标签:div include 就是 type code pac 取整 pow head
大意: 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 (贪心,模拟)
标签:div include 就是 type code pac 取整 pow head
原文地址:https://www.cnblogs.com/uid001/p/10625292.html