Codeforces 377B Priority Queue + two points

Source: Internet
Author: User

title :

Oh, this broken topic made me two hours, first test instructions a little afraid of, n person, with the ability to solve the bug, a day can only solve one, M Bug,bug has a difficulty, only a person ability is equal to this difficulty can solve, please n personal solve a problem, everyone to take the money, The quickest solution to ask not more than S dollars

Scenarios that output each bug resolved by which person

First consider the DP, found that no, then feel is greedy, then with the priority queue contact, the difficulty of the bug with the ability to solve the problem with people from the big to the small row, and then start the two-point enumeration to solve the number of days, assuming that the number of days to solve the T, then the most powerful person and spend more suitable for the From the big to the small row, and then priority queue to solve the problem of the least cost of people, every update, if he can solve the first problem, then the next t-1 a problem he can solve, the update is updated from the past, so it is definitely the best, the middle of spending more than s of the scheme can be shed, There is no way to solve the current unresolved maximum difficulty of the bug also to be shed, the last of the two enumeration can be successful is definitely the best,

Start to see if the hardest bug anyone can solve, otherwise output no

Also see if M-Day has a solution, because up to the use of M-day, if not resolved then output no

The next enumeration is the number of days

At first did not quite go to enumerate the resolution time, the result is very troublesome, later thought, knocked, the result Midway priority queue has a place hand cheap knock wrong, has been debugging the solution function, really drunk.


int n,m,s;typedef struct Node {int id;int nnum;bool operator< (const Node &AMP;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<m;i++) {Cin>>bug[i].nnum;bug[i] . id = i + 1;MAXN = max (maxn,bug[i].nnum);} for (int i=0;i<n;i++) {cin>>stu[i].ablity;stu[i].id = i + 1;} for (int i=0;i<n;i++) Cin>>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<node> q;for (int i=0,j=0;i<m;i+=t) {for (; j<n;j++) {if (Stu[j]. Ablity >= 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<m;j++) {Tmp[bug[j].id] = qq.id;mark++;if (Mark = = t) break;}} for (int i=1;i<=m;i++) Ans[i] = Tmp[i];return true;} void Cal () {BOOL flag = false;for (int i=0;i<n;i++) {if (stu[i].ablity >= maxn && stu[i].cost <= s) flag = t Rue;} 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;}


Codeforces 377B Priority Queue + two points

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.