http://www.lydsy.com/JudgeOnline/problem.php?id=2802

自己yy了一下。。。

每一次如果够那么就买。

如果不够,考虑之前买过的,如果之前买过的比当前花费的钱多,那么就去掉之前买的,变成买现在的。

如何证明?不知道QAQ

还有。。。注意开longlong。。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const ll getint() { ll r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const int N=250005;
priority_queue<pair<ll, int> > q;
ll a[N];
bool vis[N];
int main() {
int n=getint(), ans=0;
ll rest=0;
for1(i, 1, n) read(a[i]);
for1(i, 1, n) {
ll b=getint();
rest+=a[i];
if(rest>=b) rest-=b, q.push(make_pair<ll, int>(b, i)), ++ans, vis[i]=1;
else if(!q.empty()) {
ll tp=q.top().first;
if(tp>b) { rest+=tp; rest-=b; vis[i]=1; vis[q.top().second]=0; q.pop(); q.push(make_pair<ll, int>(b, i)); }
}
}
print(ans); puts("");
for1(i, 1, n) if(vis[i]) printf("%d ", i);
return 0;
}

  


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

HINT

 

Source

【BZOJ】2802: [Poi2012]Warehouse Store(贪心)的更多相关文章

  1. bzoj 2802 [Poi2012]Warehouse Store STL

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

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

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

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

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

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

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

  5. BZOJ2802: [Poi2012]Warehouse Store

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

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

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

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

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

  8. BZOJ2802——[Poi2012]Warehouse Store

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

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

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

随机推荐

  1. win7+ubuntu双系统中卸载ubuntu方法

    双系统中,如果要卸载ubuntu是不能够直接卸载的,需要使用一些特殊的方法.下面就为大家详细的介绍介绍. Step1 MBR引导区修复: 进入win7,下载个软件MbrFix,放在C:\windows ...

  2. GIT的标准文档 使用和服务介绍

    http://www.kancloud.cn/kancloud/how-to-use-github/42192 1. 探索GitHub 熟悉Git的人几乎都知道并喜欢GitHub,反过来GitHub也 ...

  3. 《ASP.NET1200例》ListView控件之修改,删除与添加

    aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...

  4. Android Unlock Patterns

    Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total ...

  5. Serialize and Deserialize Binary Tree

    Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...

  6. CSS用Id选择器在本页写样式

    <title>静夜思</title><style type="text/css">#red{color:#ff0000; font-weight ...

  7. 【转】如何用 Chrome for Android 做远程遥控 debugging

    http://blog.csdn.net/wuchengzhi82/article/details/22190435

  8. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

  9. [Android Studio] 使用本地 aar 文件

    导出aar 首先Android Library项目的gradle脚本只需要在开头声明 apply plugin: 'com.android.library' 之后就和导出apk文件一样的方法,执行 . ...

  10. [MAC] mac系统如何显示和隐藏文件

    转载地址: http://www.cnblogs.com/lm3515/archive/2010/12/08/1900271.html 显示Mac隐藏文件的命令:defaults write com. ...