BZOJ_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 <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define N 250050
int b[N],ch[N],c[N];
inline bool cmp(const int &x,const int &y) {return b[x]>b[y];}
struct A {
int b,id;
bool operator < (const A &x) const {
return b<x.b;
}
}a[N];
__gnu_pbds::priority_queue<A>q;
int n;
ll sum;
int main() {
scanf("%d",&n);
int i,x,y;
for(i=1;i<=n;i++) scanf("%d",&c[i]);
for(i=1;i<=n;i++) scanf("%d",&b[i]);
for(i=1;i<=n;i++) {
x=c[i],y=b[i];a[i].b=y; a[i].id=i;
sum+=x;
if(sum>=y) {
sum-=y; q.push(a[i]); ch[i]=1;
}else {
if(!q.empty()) {
if(q.top().b>y) sum=sum+q.top().b-y,ch[q.top().id]=0,q.pop(),q.push(a[i]),ch[i]=1;
}
}
// printf("%lld\n",sum);
}
printf("%d\n",q.size());
for(i=1;i<=n;i++) if(ch[i]) printf("%d ",i);
}

最新文章

  1. DirectShow开发快速入门之慨述
  2. consul笔记
  3. 判断s2是否能够被通过s1做循环移位(rotate)得到的字符串是否包含
  4. js控制input type=checkbox 的勾选
  5. 前端框架Bootstrap
  6. 瑞柏匡丞_免费app开发是否可行
  7. Java 内存回收机制 -说到点上了
  8. 编写一篇博文介绍COOKIE和Session的原理及异同
  9. 20171012--jq 遍历取值
  10. sass中文注释的解决方法和一些简单用法
  11. MFC绘图小实验(1)
  12. Mybatis常见面试题 一
  13. 打开AVD时报&rdquo;Data partition already in use. Changes will not persist!&rdquo;
  14. 如何进行 Python性能分析,你才能如鱼得水?
  15. JDBC 使用common-dbutiles
  16. 使用idea 搭建Spring+mybatis
  17. visual studio内置“iis”组件提取及二次开发
  18. Mockplus设计大赛获奖选手专访 | Intimate:你的专属密友音乐播放器
  19. poj 2287(贪心)
  20. 面试常见的selenium问题

热门文章

  1. Python 规范化LinkedIn用户联系人的职位名
  2. HDFS源码分析之UnderReplicatedBlocks(二)
  3. FreeRTOS在神舟IV号开发板的应用demo
  4. 【selenium+Python WebDriver API】之复选框顺序正选和顺序反选
  5. Android OkHttp的Cookie自己主动化管理
  6. fzu 2039 Pets (简单二分图 + (最大流 || 二分图))
  7. 可展开的UITableView (附源码)
  8. python 基础 8.5 re 的match对象
  9. href=http:// href=// 的区别,src=http:// src=// 的区别。 链接里不带http,链接里直接使用双斜线 // 有什么不同。http://和//有什么区别?
  10. jQuery 插件开发(1)