UVa 11729 Commando War "greedy"

Source: Internet
Author: User

Test instructions: There are n subordinates, confessed each of his subordinates to complete his corresponding tasks need bi time, and then complete the task requires Ji time,

Choose the order of the tasks, make the total time to spend the least

Because in any case, the time required to confess the N*BI is to be spent,

Then let the person who completes the task take a long time to do first, will j in descending order, update each person's task to complete the time spent

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=10005; -  - intN; + structnode{ -     intb,q; + } A[MAXN]; A  at intCMP (node N1,node n2) { -     returnN1.Q >n2.q; - } -  - intMain () { -     intKase =0; in      while(SCANF ("%d", &n)! = EOF &&N) { -          for(intI=1; i<=n;i++) scanf ("%d%d",&a[i].b,&a[i].q); toSort (A +1, a+n+1, CMP); +          -         intBeg =0, end =0, ans =0; the  *          for(inti =1; I <= n;i++){ $Beg + =a[i].b;Panax Notoginseng             if(Beg + a[i].q >= end) End = Beg +a[i].q; -              the         //printf ("i =%d Beg =%d end =%d\n", i,beg,end); +         } Aprintf"Case %d:%d\n",++Kase,max (Beg,end)); the     } +     return 0; -}
View Code

UVa 11729 Commando War "greedy"

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.