# [BZOJ1672]&&[Usaco2005 Dec]Cleaning Shifts 清理牛棚

## 描述 Description

Farmer John’s cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn. Farmer John has N (1 <= N <= 10,000) cows who are willing to do some cleaning. Because dust falls continuously, the cows require that the farm be continuously cleaned during the workday, which runs from second number M to second number E during the day (0 <= M <= E <= 86,399). Note that the total number of seconds during which cleaning is to take place is E-M+1. During any given second M..E, at least one cow must be cleaning. Each cow has 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 11 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 is covered by at least one cow and which minimizes the total salary that goes to the cows.

## 输入格式 InputFormat

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.

## 输出格式 OutputFormat

Line 1: a single integer that is either the minimum total salary to get the barn cleaned or else -1 if it is impossible to clean the barn.

5 0 4
2 2 2
1 1 1
4 4 4
0 0 0
3 3 3

10

BZOJ 1672

## 代码 Code

``````#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int inf=0x7fffffff/27.11;
int i,j,t,n,m,l,r,k,z,y,x;
{
int k=1;x=0;char ch=getchar();
for (;ch<'0' || ch>'9';ch=getchar()) if (ch=='-') k=-1;
for (;ch>='0' && ch<='9';ch=getchar()) x=x*10+ch-'0';
x*=k;
}
struct cow
{
int ts,te,s;
bool operator < (const cow& tmp) const
{
return (ts!=tmp.ts)?(ts<tmp.ts):((te!=tmp.te)?(te<tmp.te):(s<tmp.s));
}
}a[10005];
int e;
int f[10005];
int ans;
int main()
{