码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 746F Music in Car

时间:2019-03-29 00:58:32      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:sign   ++   begin   mes   def   https   using   mod   std   

Music in Car

用两个Set维护一下尺取的过程。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);

int n, w, k, a[N], t[N];
bool flag[N];

set<PII> Set1;
set<PII> Set2;

int main() {
    scanf("%d%d%d", &n, &w, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &t[i]);
    int now = 0, tmp = 0, ans = 0;
    for(int i = 1, j = 1; i <= n; ++i){
        now += (1 + t[i]) >> 1;
        tmp += a[i];
        if(Set1.size() < w){
            Set1.insert(mk(t[i] >> 1, i));
            flag[i] = true;
        }else{
            if((*Set1.begin()).fi < (t[i] >> 1)){
                PII tt = *Set1.begin();
                Set1.erase(Set1.begin());
                now += tt.fi;
                flag[tt.se] = false;
                Set1.insert(mk(t[i] >> 1, i));
                flag[i] = true;
                Set2.insert(tt);
            }
            else{
                now += t[i] >> 1;
                Set2.insert(mk(t[i] >> 1, i));
            }
        }
        while(now > k){
            if(flag[j]){
                now -= (t[j] + 1) >> 1;
                Set1.erase(mk(t[j] >> 1 , j));
                while(Set2.size() && (*Set2.rbegin()).se < j) Set2.erase(*Set2.rbegin());
                if(Set2.size()){
                    PII tt = *Set2.rbegin();Set2.erase(*Set2.rbegin());
                    now -= tt.fi;
                    Set1.insert(tt);
                    flag[tt.se] = true;
                }
            }
            else{
                now -= t[j];
            }
            tmp -= a[j];
            ++j;
        }
        ans = max(ans, tmp);
    }
    printf("%d\n", ans);
    return 0;
}

/*
*/

 

Codeforces 746F Music in Car

标签:sign   ++   begin   mes   def   https   using   mod   std   

原文地址:https://www.cnblogs.com/CJLHY/p/10618745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!