CodeForces 377B priority queue + binary

Source: Internet
Author: User

CodeForces 377B priority queue + binary

Question:

Well, I have been engaged in this broken question for two hours. First, I was a little scared about the question. n people have the ability to solve bugs. Only one or more bugs can be solved in one day, A bug is difficult. Only one person with the same abilities can solve the problem. Ask n people to solve the problem. Everyone must take the money, the shortest solution when the number of s yuan is not more

Which of the following solutions can output each bug?

I first considered DP and found that I couldn't do it. Then I felt greedy. Then I contacted the priority queue to increase the difficulty of the bug and the capability of solving the problem, then we start to solve the number of days by means of two-point enumeration. If the number of days is t, then the person with the most severe problem and who spends the most appropriate time can use t at most, from large to small, and then the first queue can solve the problem of the least cost of people, every update, if he can solve the first problem, then the next T-1 problem he can solve, updates are updated from the past to the future, so they must be the best. solutions that spend more than s in the middle can be removed, and there is no way to solve the most difficult bug that has not yet been solved, the last successful result of the binary enumeration is certainly the best,

First, check whether the most difficult bug can be solved. Otherwise, No is output.

Check whether there is a solution for m days, because the maximum is m days. If the solution cannot be solved, output no

Next, we will enumerate the number of days.

At the beginning, it was not quite time to enumerate and solve the problem. The result was very troublesome. Later I thought about it and knocked it out. In the middle of the process, there was a place in the queue where I was wrong, I have been debugging and solving the function. It's really drunk ..


int n,m,s;typedef struct Node {int id;int nnum;bool operator<(const Node &aa)const {return nnum > aa.nnum;}};Node bug[100000 + 55];typedef struct NODE {int id;int ablity;int cost;bool operator<(const NODE & aa)const {return cost > aa.cost;}};NODE stu[100000 + 55];int maxn;int ans[100000 + 55],tmp[100000 + 55];void init() {memset(bug,0,sizeof(bug));memset(stu,0,sizeof(stu));}bool input() {while(cin>>n>>m>>s) {maxn = -1;for(int i=0;i
 
  >bug[i].nnum;bug[i].id = i + 1;maxn = max(maxn,bug[i].nnum);}for(int i=0;i
  
   >stu[i].ablity;stu[i].id = i + 1;}for(int i=0;i
   
    >stu[i].cost;return false;}return true;}bool cmp(NODE x,NODE y) {return x.ablity > y.ablity;}bool isok(int t) {int ret = 0;priority_queue
    
      q;for(int i=0,j=0;i
     
      = bug[i].nnum)q.push(stu[j]);else break;}if(q.size() == 0)return false;NODE qq = q.top();q.pop();ret += qq.cost;if(ret > s)return false;int mark = 0;for(int j=i;j
      
       = maxn && stu[i].cost <= s)flag = true;}if(!flag) {puts("NO");return;}sort(bug,bug + m);sort(stu,stu + n,cmp);int cc = 0;if(!isok(m)){puts("NO");return ;}int l = 1,r = m;while(l <= r) {int mid = (l + r)>>1;if(isok(mid))r = mid - 1;else l = mid + 1;}puts("YES");for(int i=1;i<=m;i++)printf("%d%c",ans[i],i == m?'\n':' ');}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}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.