Poj3171--cleaning Shifts

Source: Internet
Author: User

Cleaning Shifts
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2813 Accepted: 976

Description

Farmer John ' s cows, pampered since birth, has reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, have no choice but hire some of the cows to clean the barn.

Farmer John had n (1 <= n <=) cows who is willing to do some cleaning. Because dust falls continuously, the cows require that the farm is continuously cleaned during the workday, which runs fro M second number m to second number E during the day (0 <= m <= E <= 86,399). Note the total number of seconds during which cleaning are to take place is e-m+1. During any given second M.. E, at least one cow must is cleaning.

Each cow have submitted a job application indicating her willingness to work during a certain interval T1. T2 (where M <= T1 <= T2 <= E) for a certain salary of S (where 0 <= s <= 500,000). Note that a cow who indicated the interval 10..20 would work for one seconds, not 10. Farmer John must either accept or reject each individual application; He may not ask a cow to work only a fraction of the time it indicated and receive a corresponding fraction of the salary.

Find a schedule in which every second of the workday are covered by at least one cow and which minimizes the total salary T Hat goes to the cows.

Input

Line 1:three space-separated integers:n, M, and E.

Lines 2..n+1:line i+1 describes cow I ' s schedule with three space-separated integers:t1, T2, and S.

Output

Line 1:a A single integer that's either the minimum total salary to get the barn cleaned or else-1 if it's impossible to Clean the barn.

Sample Input

3 0 40 2 33 4 20 0 1

Sample Output

5

Hint

Explanation of the sample:

FJ have three cows, and the barn needs to being cleaned from second 0 to second 4. The first cow is willing to work during seconds 0, 1, and 2 for a total salary of 3, etc.

Farmer John can hire the first and the cows.

Source

Usaco 2005 December Silver

For a long time ah, do not know where the mistake has been WA, and then simply overturned
First, the optimal value of each segment can be concentrated at the right end, so we can only consider the right side of the value

DP[SEG[I].R] = min (dp[x] + seg[i].c)

#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace std;const int N = 100010;const long inf = 0X7FFFFFF F;struct node{int L, R;long long Val;} Tree[n << 2], Seg[n];long long Dp[n];int CMP (Node A, Node B) {return A.R < B.R;} void build (int p, int l, int r) {tree[p].l = L;TREE[P].R = R;tree[p].val = inf;if (L = = r) {return;} int mid = (L + R) >> 1;build (P << 1, L, mid); build (P << 1 | 1, mid + 1, r);} void Update (int p, int pos, Long long val) {if (tree[p].l = = TREE[P].R) {tree[p].val = min (Tree[p].val, Val); return;} int mid = (tree[p].l + tree[p].r) >> 1;if (pos <= mid) {Update (P << 1, POS, val);} Else{update (P << 1 | 1, POS, val);} tree[p].val = min (tree[p << 1].val, tree[p << 1 | 1].val);} Long Long query(int p, int l, int r) {if (l <= tree[p].l && TREE[P].R <= r) {return tree[p].val;} int mid = (tree[p].l + tree[p].r) >> 1;if (R <= mid) {return query (P << 1, L, r);} else if (L > Mid) {return query (P << 1 | 1, L, r);} Else{return min (Query (P << 1, L, mid), query (P << 1 | 1, mid + 1, r));}} int main () {int L, R, N;while (~scanf ("%d%d%d", &n, &l, &r)) {for (int i = 0; i < n; ++i) {scanf ("%d%d%lld", & AMP;SEG[I].L, &AMP;SEG[I].R, &seg[i].val);} Sort (SEG, SEG + N, CMP), build (1, 1, R + 1), for (int i = 0; I <= 90000; ++i) {dp[i] = inf;} for (int i = 0; i < n; ++i) {if (SEG[I].R < L) {continue;} if (SEG[I].L <= l) {DP[SEG[I].R] = min (DP[SEG[I].R], seg[i].val);} else {DP[SEG[I].R] = min (DP[SEG[I].R], query (1, SEG[I].L, SEG[I].R) + seg[i].val);} Update (1, SEG[I].R + 1, DP[SEG[I].R]);} Long Long ans = inf;for (int i = r; I <= SEG[N-1].R; ++i) {ans = min (ans, dp[i]);} if (ans >= inf) {printf (" -1\n");} else{printf ("%lld\n", ans);}} RetUrn 0;} 


Poj3171--cleaning Shifts

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.