51nod:1689 Shopping

Source: Internet
Author: User

Original title Link: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1689

First want to enumerate the end of the shopping, and then open two large root heap maintenance b value, respectively, to ensure that the favorite store not less than K, as well as the premise of the shop as much as possible. The implementation is to maintain the first heap element to K, each element added, if C is 1, it is thrown into the first heap, and the heap is thrown to the top of the second, C is 0 directly thrown into the second. If the sum of the element B values of the two heaps exceeds T, the element is deleted from the second heap.

But the final element of the deletion of this writing is likely to delete the points that contribute to the answer, and then to maintain the lost elements, each time a difference, and then T.

So consider each delete element to see the third heap and the second heap merits and demerits, delete the useless elements, you can save a lot of useless calculation.

#include <queue>#include<cstdio>#include<algorithm>#defineMN 100001using namespacestd;intRead_p,read_ca;inlineintRead () {read_p=0; read_ca=GetChar ();  while(read_ca<'0'|| Read_ca>'9') read_ca=GetChar ();  while(read_ca>='0'&&read_ca<='9') read_p=read_p*Ten+read_ca- -, read_ca=GetChar (); returnread_p;}intn,m,k,a[mn],b[mn],mmh=-1, A;Long Longt=0;p Riority_queue<int>q,q,s;intMain () {registerinti; N=read (); M=read (); k=read ();  for(i=1; i<=n;i++) a[i]=read ();  for(i=1; i<=n;i++) b[i]=read ();  for(i=1; i<=n;i++){        if(Read ())if(int(Q.size ()) <k) Q.push (B[i]);ElseQ.push (B[i]), Q.push (Q.top ()), Q.pop ();ElseQ.push (B[i]); T+=B[i]; if(int(Q.size ()) <k)Continue;  while(t+a[i]>m&& (! Q.empty ())) T-=q.top (), S.push (-q.top ()), Q.pop ();  while(! S.empty () &&t+a[i]-s.top () <=m) t-=s.top (), Q.push (-s.top ()), S.pop ();  while(! S.empty () &&-s.top () <Q.top ()) {T-=s.top (); Q.push (-s.top ());            S.pop ();  while(t+a[i]>m&& (! Q.empty ())) T-=q.top (), S.push (-q.top ()), Q.pop (); }        if(t+a[i]<=m&&k+int(Q.size ()) >mmh) mmh=k+int(Q.size ()); } printf ("%d\n", MMH);}
View Code

lYK like to go shopping.

But lYK time is limited, only t units of time.

lYK from shop 1th, walk from shop 1th to the no. I shop will costai Units of time, these shops formed a straight line, so lYK from the I shop to i+1 shop time spentai+1−ai 。 If you choose to go shopping, you need to spend bI 's time. For the I store, lYK has an evaluation of the value of CI , whether I like this shop.

lYK want to visit the endless streets for a limited period of time, which is of course impossible.

It has a goal, will walk into the shop in the cI and add up, to make this value ≥ K, on this basis, can stroll more stores the better.

It wants to know how many stores can be visited.

If the lYK is not met, output-1.

Input
The first row of three integers n (1<=n<=100000), T (1<=t<=10^9), K (0<=k<=n). The next line of n counts, representing AI (a1=0,a1<a2<...<an<=10^9). The next line of N is the number, representing BI (1<=bi<=10^9). The next line of N is the number representing CI (0<=ci<=1).
Output
One line represents the answer.
Input example
4 11 10 1 2 101 1 1 10 0 0 1
Output example
1

51nod:1689 Shopping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.