51nod 1099 Task Execution order (greedy algorithm)

Source: Internet
Author: User

Title: Portal.

Test instructions: Chinese question.

R[i]-o[i] Advanced lines with large values. The counter-proof method: If the big later, will cause the space to increase, so a certain big is first.

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespaceStd;typedefLong Longll;structsa{ll R,o,c;} data[100005];BOOLCMP (sa X,sa y)//Note that this sort method has a large difference in the advanced line{    returnX.c>y.c;}intMain () {ll n;  while(cin>>N) { for(intI=0; i<n; i++) {cin>>data[i].r>>data[i].o;//Note (O[i]<r[i]) This is important .data[i].c=data[i].r-DATA[I].O; } sort (Data,data+n,cmp); ll ans=0, tmp=0;  for(intI=0; i<n; i++) {ans=max (ans,tmp+DATA[I].R); TMP+=DATA[I].O; } cout<<ans<<Endl; }    return 0;}

51nod 1099 Task Execution order (greedy algorithm)

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.