http://www.lydsy.com/JudgeOnline/problem.php?id=2802
Oneself yy a bit ...
Buy it every time if it's enough.
If not enough, consider the previous purchase, if you have bought more than the current cost of money, then remove the previous buy, become buy now.
How to prove? I don't know, qaq.
And also... Note Open 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=get char (); 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;llA[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
There is a store specializing in a commodity, considering the continuous n days.
I will be in the morning of the purchase of AI products, at noon there will be customers need to buy BI products, can choose to meet customer requirements, or ignore him.
If you want to meet the needs of customers, you must have enough inventory. The maximum number of customer needs to be met.
Input
The first line is a positive integer n (n<=250,000).
The second row n integers a1,a2,... An (0<=ai<=10^9).
The third row n integers b1,b2,... Bn (0<=bi<=10^9).
Output
The first line is a positive integer k, which indicates that it can meet the needs of K customers.
The second row, K, increments the positive integer x1,x2,..., Xk, indicating that the Xk days of the x1,x2,..., to meet the customer's needs respectively.
Sample INPUT6
2 2 1 2 1 0
1 2 2 3 4 4
Sample OUTPUT3
1 2 4
HINT Source
Acknowledgement Oimaster
"Bzoj" 2802: [Poi2012]warehouse Store (greedy)