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