bzoj2802

2 篇文章 0 订阅

2802: [Poi2012]Warehouse Store

Time Limit: 10 Sec  Memory Limit: 64 MBSec  Special Judge
Submit: 560  Solved: 258
[Submit][Status][Discuss]

Description


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

Input

第一行一个正整数n (n<=250,000)。
第二行n个整数A1,A2,...An (0<=Ai<=10^9)。
第三行n个整数B1,B2,...Bn (0<=Bi<=10^9)。

Output

第一行一个正整数k,表示最多能满足k个顾客的需求。
第二行k个依次递增的正整数X1,X2,...,Xk,表示在第X1,X2,...,Xk天分别满足顾客的需求。

Sample Input

6
2 2 1 2 1 0
1 2 2 3 4 4
 

Sample Output

3
1 2 4

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<queue>
#define int long long
using namespace std;
const int N=250005;
struct node{
    int cost,xh;
    friend bool operator < (node i,node j){
        return i.cost<j.cost;
    }
}c[N];
priority_queue <node> q;
int n,w[N],ans,kc,an[N],len;
main (){
    scanf ("%lld",&n);
    for (int i=1;i<=n;++i)scanf ("%lld",&w[i]);
    for (int i=1;i<=n;++i){
        scanf ("%lld",&c[i].cost);
        kc+=w[i];c[i].xh=i;
        if (kc>=c[i].cost){
            kc-=c[i].cost;
            ans++;
            q.push(c[i]);
        }
        else {
            if (q.empty())continue;
            node tmp=q.top();
            if (tmp.cost>c[i].cost){
                kc+=tmp.cost-c[i].cost;
                q.pop();
                q.push(c[i]);
            }
        }
    }
    printf ("%lld\n",ans);
    while (!q.empty()){
        an[++len]=q.top().xh;
        q.pop();
    }
    sort(an+1,an+len+1);
    for (int i=1;i<=len;++i)
        printf ("%lld ",an[i]);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值