The third round of Tencent marathon semi-finals, the story of the HDOJ-4544 series-eliminating rabbits

Source: Internet
Author: User

Greedy + priority queue Maintenance

Sort all rabbits first... Sort all arrows by damage...

When doing this, the rabbit with a high blood volume will be able to get rid of the rabbit and consume the smallest arrows...

Directly do... timeout... and poor maintenance... introduce priority queue...

Program:

#include<iostream>#include<cmath>#include<stack>#include<queue>#include<set>#include<algorithm>#include<stdio.h>#define ll long long#define oo 1000000000using namespace std;struct node{       ll d,p;       bool operator < (const node &x) const       {              return p>x.p;       }}r[100005];ll n,m,b[100005];priority_queue<node> myqueue;bool cmp(node a,node b){       return a.d<b.d;}int main(){        ll i,h,ans;        node p;       while (~scanf("%I64d%I64d",&n,&m))       {              for (i=1;i<=n;i++) scanf("%I64d",&b[i]);              for (i=1;i<=m;i++) scanf("%I64d",&r[i].d);              for (i=1;i<=m;i++) scanf("%I64d",&r[i].p);              sort(b+1,b+1+n);              sort(r+1,r+1+m,cmp);               while (!myqueue.empty()) myqueue.pop();              h=m;              ans=0;              for (i=n;i>=1;i--)              {                     while (h && r[h].d>=b[i]) myqueue.push(r[h]),h--;                     if (myqueue.empty())                      {                             printf("No\n");                             goto A;                     }                     p=myqueue.top();                     myqueue.pop();                     ans+=p.p;              }              printf("%I64d\n",ans);               A: ;       }       return 0;}
Related Article

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.