Ultraviolet A 11729 (13.09.09)

Source: Internet
Author: User

Question: it takes time to brainwash T soldiers and ask them to brainwash their work. Just get out of work after A's brain and obey the work. The work time is B; how long does it take for all soldiers to finish their brains and finish all their work? Key Point: After training a soldier, the soldier has gone to do things. At this time, the next practice can be trained: Obviously, we need to find the longest time to do things. In this way, when doing things, he can train other soldiers to save time, so he first ranks the work time and then simulates various situations ~ Don't mess up, don't mess up! AC code:

#include<stdio.h>  #include<algorithm>    using namespace std;    struct soldier {      int A;      int B;  }s[1234];    int cmp(soldier a, soldier b) {      return a.B > b.B;  }    int cas = 0;    int main() {      int T;      int sum;      while(scanf("%d", &T) != EOF && T) {          int t1, t2;          sum = 0;          for(int i = 0; i < T; i++)              scanf("%d %d", &s[i].A, &s[i].B);          sort(s, s+T, cmp);          for(int i = 0; i < T; i++) {              if(i == 0) {                  sum += s[i].A;                  t1 = s[i].B;              }              if(i != 0) {                  t2 = s[i].A + s[i].B;                  if(t2 > t1) {                          sum += s[i].A;                          t1 = s[i].B;                  }                  else {                      t1 = t1 - s[i].A;                      sum += s[i].A;                  }              }          }          sum += t1;          printf("Case %d: ", ++cas);          printf("%d\n", sum);      }      return 0;  }  

 

 

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.