Codeforces Round #437 (Div. 2, based on Memsql start[c]up 3.0-round 2) c. Ordering Pizza

Source: Internet
Author: User
Tags memsql

Test instructions: There are 2 kinds of Pizzaa and B, there are n individuals, each pizz divided into s pieces, give everyone needs to eat s piece, eat a piece of a to get x happiness, eat a B to get y happiness, ask in the premise of the purchase of the least pizza to get the maximum happiness value

Idea: Note that everyone can eat A and b at the same time, when x>=y, we choose a, otherwise choose B, see this time to buy pizza, and all pieces of pizza buy, otherwise, we separate, for the redundant a, we buy B, with the smallest x-y to change, B also the same

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong Longll;4 Const intn=1e5+ -;5 6 structnode{7 ll S,x;8 node (ll xx,ll yy) {9s=xx;x=yy;Ten     } One }; A ll N,s; -Vector<node>b; -ll sum1=0, sum2=0, sum=0; the BOOLCMP (node P,node q) { -     returnp.x<q.x; - } -  + BOOLCheck () { -ll x1=sum1/s,x2=sum2/s,x3= (SUM1+SUM2)/S; +     if(sum1%s) x1++; A     if(sum2%s) x2++; at     if((sum1+sum2)%s) x3++; -     if(X1+X2==X3)return true ; -     Else return false; - } -  - intMain () { inCin>>n>>S; - ll x, y, Z; to      for(intI=1; i<=n;i++){ +scanf"%lld%lld%lld",&x,&y,&z); -         if(y>=z) { theA.push_back ({x,y-z}); *sum1+=x*1LL; $sum+= (x*y) *1LL;Panax Notoginseng         } -         Else { theB.push_back ({x,z-y}); +sum2+=x*1LL; Asum+= (1LL) *x*Z; the         } +     } -     if(check ()) { $cout<<sum<<endl;return 0; $     } - sort (A.begin (), A.end (), CMP); - sort (B.begin (), B.end (), CMP); the    //cout<<sum<< "" <<sum1<< "" <<sum2<<endl; -ll ans1=sum,ans2=sum;Wuyill xx=sum1%S; the      for(intI=0; I<a.size (); i++){ -ll min=min (xx,a[i].s); Wuans1-=min*a[i].x; -xx-=Min; About         if(xx==0) Break; $     } -ll yy=sum2%S; -      for(intI=0; I<b.size (); i++){ -ll min=min (yy,b[i].s); Aans2-=min*b[i].x; +yy-=Min; the         if(yy==0) Break; -     } $Cout<<max (ANS1,ANS2) <<Endl; the}

Codeforces Round #437 (Div. 2, based on Memsql start[c]up 3.0-round 2) c. Ordering Pizza

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.