恩。。。贪心来着。。。

我们先贪心当天能不能满足客户要求,如果能就尽量满足。

好了现在不能满足怎么办?作为一个无良的商家,可以退掉以前的订单。。。(现实中真的可以?、、、)

为了让当前剩余货物总量尽可能大,当然是退掉之前要求最高的订单喽,于是用堆维护一下就好了

注意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 }
View Code

 

posted on 2014-12-07 21:21  Xs酱~  阅读(252)  评论(0编辑  收藏  举报