Sicily10359 (priority queue)

Source: Internet
Author: User


#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <

Queue> using namespace std; struct object {int w,v;}
A[300005];

int bag[300005];

BOOL Cmp1 (struct object A,struct object b) {return a.w<b.w;}
  	Class Cmp2 {Public:bool operator () (struct object A,struct object b) {return a.v<b.v;

}
};
    int main () {int n,m;
    int i,j;
    Priority_queue<struct object,vector<struct object>,cmp2> Q;
    scanf ("%d%d", &n,&m);

    for (i=0;i<n;i++) scanf ("%d%d", &AMP;A[I].W,&AMP;A[I].V);
      
    for (i=0;i<m;i++) scanf ("%d", &bag[i]);
    Sort (A,A+N,CMP1);
    
    Sort (bag,bag+m);
    int apos=0;
    Long Long ans=0;
    		for (i=0;i<m;i++) {while (Apos<n && a[apos].w<=bag[i]) {Q.push (A[apos]);
    	apos++; } if (!
	    	Q.empty ()) {ans+=q.top (). V;
      Q.pop ();
}} printf ("%lld\n", ans);  }  


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.