首页 > 代码库 > BZOJ2802 [Poi2012]Warehouse Store
BZOJ2802 [Poi2012]Warehouse Store
恩。。。贪心来着。。。
我们先贪心当天能不能满足客户要求,如果能就尽量满足。
好了现在不能满足怎么办?作为一个无良的商家,可以退掉以前的订单。。。(现实中真的可以?、、、)
为了让当前剩余货物总量尽可能大,当然是退掉之前要求最高的订单喽,于是用堆维护一下就好了
注意long long什么的就好了
1 /************************************************************** 2 Problem: 2802 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:600 ms 7 Memory:5108 kb 8 ****************************************************************/ 9 10 #include <cstdio>11 #include <queue>12 13 using namespace std;14 typedef long long ll;15 const int N = 250005;16 17 struct data {18 int w, num;19 data() {}20 data(int _w, int _n) : w(_w), num(_n) {}21 22 inline bool operator < (const data &x) const {23 return num == x.num ? w < x.w : num < x.num;24 }25 };26 27 int n, ans;28 int a[N], b;29 bool u[N];30 ll now;31 priority_queue <data> h;32 33 inline int read() {34 int x = 0;35 char ch = getchar();36 while (ch < ‘0‘ || ‘9‘ < ch)37 ch = getchar();38 while (‘0‘ <= ch && ch <= ‘9‘) {39 x = x * 10 + ch - ‘0‘;40 ch = getchar();41 }42 return x;43 }44 45 int main() { 46 int i;47 n = read();48 for (i = 1; i <= n; ++i)49 a[i] = read();50 for (i = 1; i <= n; ++i) {51 b = read();52 now += a[i];53 if (now > b)54 h.push(data(i, b)), now -= b, u[i] = 1, ++ans;55 else if (!h.empty() && h.top().num > b) {56 now += h.top().num - b, u[i] = 1, u[h.top().w] = 0;57 h.pop(), h.push(data(i, b));58 }59 }60 printf("%d\n", ans);61 for (i = 1; i <= n; ++i)62 if (u[i]) printf("%d ", i);63 return 0;64 }
BZOJ2802 [Poi2012]Warehouse Store
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。