2802: [Poi2012]Warehouse Store
Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 478 Solved: 222
[ 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
2 2 1 2 1 0
1 2 2 3 4 4
Sample Output
3
1 2 4
1 2 4
HINT
Source
可以贪心去做,,尽可能满足今天的顾客的需求,如果货物不够,就把之前的一个需求最大的删掉
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 2E5 + 5E4 + 50;
typedef long long LL;
int n,Ans,A[maxn],B[maxn];
bool bo[maxn];
LL res;
struct data{
int pos,Num; data(){}
data(int pos,int Num): pos(pos),Num(Num){}
bool operator < (const data &b) const {return Num < b.Num;}
};
priority_queue <data> Q;
int getint()
{
char ch = getchar(); int ret = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9')
ret = ret*10 + ch - '0',ch = getchar();
return ret;
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
n = getint(); int tot = 0;
for (int i = 1; i <= n; i++) A[i] = getint();
for (int i = 1; i <= n; i++) B[i] = getint();
for (int i = 1; i <= n; i++)
{
res += 1LL*A[i];
if (res >= B[i]) res -= 1LL*B[i],++Ans,Q.push(data(i,B[i]));
else if (!Q.empty())
{
data k = Q.top();
if (k.Num > B[i])
{
Q.pop(); Q.push(data(i,B[i]));
res += 1LL*(k.Num - B[i]);
}
}
}
cout << Ans << endl;
while (!Q.empty()) bo[Q.top().pos] = 1,Q.pop();
for (int i = 1; i <= n; i++)
if (bo[i])
{
++tot;
if (tot < Ans) printf("%d ",i);
else cout << i;
}
return 0;
}