# Sicily 13983. Milk Scheduling

Source: Internet
Author: User

13983. Milk Scheduling Constraints

Time limit:1 secs, Memory limit:256 MB

Description

Farmer John has N cows this need to being milked (1 <= N <=), each of the which takes only one unit of time to milk.

Being impatient animals, some cows would refuse to being milked if Farmer John waits too long to milk them. More specifically, cow I produces g_i gallons of milk (1 <= g_i <=), but only if she's milked before a Deadlin E at time d_i (1 <= d_i <= 10,000). Time starts at t=0, so at the most x total cows can is milked prior to a deadline at time T=x.

Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally.

Input

* Line 1:the value of N.

* Lines 2..1+n:line i+1 contains the integers g_i and d_i.

Output

* Line 1:the Maximum number of gallons of milk Farmer John can obtain.

Sample Input
`410 37 58) 12 1`
Sample Output
`25`
Hint

In the sample, there is 4 cows. The first produces gallons of milk if milked by time 3, and so on. Farmer John Milks Cow 3 first, giving up on cow 4 since she cannot being milked by hers deadline due to the conflict with cow 3. Farmer John then milks cows 1 and 2.

Problem Source

2015 every Monday match sixth game

According to G Big first, D small priority, for a cow, priority to the point of time as close as possible to D, so as far as possible delay, give the other cows full time ...

`#include <iostream> #include <algorithm>using namespace std;struct cow {int g, d;cow (int g = 0, int d = 0) {thi S->g = G;this->d = D;}}; BOOL CMP (const COW & C1, Const Cow & C2) {if (c1.g = = c2.g) return c1.d < C2.d;else return c1.g > c2.g;} Cow c[10005];bool used[10005];int havetime (int d) {for (int i = D; i > 0; i--) if (!used[i]) return I;return 0;} int main () {Std::ios::sync_with_stdio (false), int n;cin >> n;for (int i = 0; i < n; i++) cin >> C[I].G >& Gt C[i].d;sort (c, C + N, CMP); int t = 4, ans = 0;for (int i = 0; i < n; i++) {int feedday = Havetime (C[I].D); if (Feedday) {Used[feedday] = True;ans + = C[I].G;}} cout << ans << endl;return 0;}`

Sicily 13983. Milk Scheduling

Related Keywords:

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.