简友广场持续输出需要动力坚持写作356

bzoj2802

2020-06-09  本文已影响0人  信息学小屋

2802: [Poi2012]Warehouse Store

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;
}
上一篇 下一篇

猜你喜欢

热点阅读