Bzoj1620/p2920 [usaco 08nov] Time Management

Source: Internet
Author: User

P2920 [usaco 08nov] Time Management

Apparently greedy.

Sort by deadline from large to small, and then fill the time in sequence.

If the last time is negative, there is no solution.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # define re register 6 using namespace STD; 7 int max (int A, int B) {return A> B? A: B;} 8 struct data {9 int T, DL; 10 bool operator <(const Data & TMP) const {return DL> TMP. DL;} 11} A [1002]; 12 int n, TT, ans; 13 int main () {14 scanf ("% d", & N ); 15 For (Re int I = 1; I <= N; ++ I) scanf ("% d", & A [I]. t, & A [I]. DL); 16 sort (a + 1, A + n + 1); TT = A [1]. DL; 17 for (Re int I = 1; I <= N; ++ I) {18 TT = min (TT, a [I]. DL); TT-= A [I]. t; // note that the command is completed before deadline, so min19} TT <0? Printf ("-1"): printf ("% d", TT); 20 return 0; 21}
View code

 

Bzoj1620/p2920 [usaco 08nov] Time Management

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.