1、题目巨短,自己看看吧

2、分析:这道题,想了半天dp还是想不到,最后看题解发现是个贪心的思想,我们维护一个堆,如果这个人不能加入就把他和堆上最大的进行比较,然后搞搞就行了

#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 250010
#define LL long long

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

struct Node{
    int d, u;

    inline bool operator < (const Node& rhs) const{
        return d < rhs.d;
    }
};

priority_queue<Node> Q;

int A[M], B[M];
int tot, a[M];

int main(){
    int n = read();
    for(int i = 1; i <= n; i ++) A[i] = read();
    for(int i = 1; i <= n; i ++) B[i] = read();
    LL ans = 0;
    for(int i = 1; i <= n; i ++){
        ans += A[i];
        if(ans >= B[i]) ans -= B[i], Q.push((Node){B[i], i});
        else if(!Q.empty() && Q.top().d > B[i]){
            ans += Q.top().d; Q.pop();
            ans -= B[i], Q.push((Node){B[i], i});
        }
    }
    while(!Q.empty()){
    //  printf("%d\n", Q.top().d);
        a[++ tot] = Q.top().u; Q.pop();

    }
    sort(a + 1, a + tot + 1);
    printf("%d\n", tot);
    for(int i = 1; i < tot; i ++) printf("%d ", a[i]);
    if(tot) printf("%d\n", a[tot]);
    return 0;
}


BZOJ2802——[Poi2012]Warehouse Store的更多相关文章

  1. BZOJ2802: [Poi2012]Warehouse Store

    2802: [Poi2012]Warehouse Store Time Limit: 10 Sec  Memory Limit: 64 MBSec  Special JudgeSubmit: 121  ...

  2. BZOJ2802 [Poi2012]Warehouse Store 【贪心】

    题目链接 BZOJ2802 题解 这样的问题通常逆序贪心 每个\(A[i]\)只能用来满足后面的\(B[i]\) 就用当前\(A[i]\)不断提供给最小的\(B[i]\)即可 用一个堆维护 #incl ...

  3. bzoj2802 [Poi2012]Warehouse Store 贪心+堆

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2802 题解 我一开始想到了一个比较麻烦的做法. 把每一天按照 \(b_i\) 从小到大排序,\ ...

  4. 【BZOJ 2802】 2802: [Poi2012]Warehouse Store (贪心)

    2802: [Poi2012]Warehouse Store Description 有一家专卖一种商品的店,考虑连续的n天.第i天上午会进货Ai件商品,中午的时候会有顾客需要购买Bi件商品,可以选择 ...

  5. bzoj 2802 [Poi2012]Warehouse Store STL

    [Poi2012]Warehouse Store Time Limit: 10 Sec  Memory Limit: 64 MBSec  Special JudgeSubmit: 621  Solve ...

  6. [bzoj2802][Poi2012]Warehouse Store_贪心_堆

    Warehouse Store bzoj-2802 Poi-2012 题目大意:一家商店的连续n天内,每一天会进货$a_i$个,有且只有一个客人回来买$b_i$个,问至多满足多少人. 注释:$1\le ...

  7. 【bzoj2802】[Poi2012]Warehouse Store 贪心+堆

    题目描述 有一家专卖一种商品的店,考虑连续的n天.第i天上午会进货Ai件商品,中午的时候会有顾客需要购买Bi件商品,可以选择满足顾客的要求,或是无视掉他.如果要满足顾客的需求,就必须要有足够的库存.问 ...

  8. 【BZOJ】2802: [Poi2012]Warehouse Store(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2802 自己yy了一下... 每一次如果够那么就买. 如果不够,考虑之前买过的,如果之前买过的比当前花 ...

  9. BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心

    BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心 Description 有一家专卖一种商品的店,考虑连续的n天. 第i天上午会进货Ai件商品,中午的时候会有顾客需要购买 ...

随机推荐

  1. Java GC系列

    一个国外站点的Java JVM调优系列 下面是国内站点翻译的 http://www.importnew.com/1993.html

  2. [LeetCode] Count of Smaller Numbers After Self 计算后面较小数字的个数

    You are given an integer array nums and you have to return a new counts array. The counts array has ...

  3. 【WPF】GridLengthAnimation

    参考 : http://zhidao.baidu.com public class GridLengthAnimation : AnimationTimeline { public static re ...

  4. array

    1.array() //创建数组 2.array_change_key_case($arr,CASE_UPPER); //将键名全部大写,不加参数全变小写--没啥用 3.array_chunk($ar ...

  5. 【日常操作记录】Asp.Net Core 的一些基本操作或属性

    用于记录在项目中使用到的方法.属性.操作,持续更新中 静态文件的使用 在项目中静态文件的使用需要在Startup中的Configure方法中增加: //使用静态文件 app.UseStaticFile ...

  6. replace和translate的用法

    select replace ('111222333444','222','888') from dual;with tmp as(select 'aabb/123\:cde工人' s from du ...

  7. 阻止pc端浏览器缩放js代码

    阻止pc端浏览器缩放js代码 众所周知:移动端页面禁止用户缩放界面只需加上<meta name="viewport" content="user-scalable= ...

  8. 记录在linux下的wine生活

    记录在linux下的windows生活 本篇内容涉及QQ.微信.Office的安装配置 QQ: 到deepin下载轻聊版. 如果安装了crossover,那么将其中opt/cxoffice/suppo ...

  9. mybatis-generator指定列进行自动生成代码

    目前mybatis-generator已经升级到1.3.3,功能比较强大,但是目前从table中如果字段较多可以选择忽略生产的字段(通过ignoreColumn属性实现,http://generato ...

  10. 统计单词数(WordCount)

    1.首先新建两个文件夹: 往文件夹添加内容: 2.启动hadoop-查看是否启动成功. 3.先对nameNode进行初始化. 4.查看hadoop下面有哪些文件. 5.在hadoop目录下创建inpu ...