Intervals
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 23864 |
|
Accepted: 9048 |
Description
You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.
Write a program that:
reads the number of intervals, their end points and integers c1, ..., cn from the standard input,
computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,...,n,
writes the answer to the standard output.
Input
The first line of the input contains an integer n (1 <= n <= 50000) -- the number of intervals. The following n lines describe the intervals. The (i+1)-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.
Output
The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i=1,2,...,n.
Sample Input
5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1
Sample Output
6
题意:
给出数轴上的n个区间[ai,bi],每个区间都是连续的int区间。现在要在数轴上任意取一堆元素,构成一个元素集合V要求每个区间[ai,bi]和元素集合V的交集至少有ci不同的元素求集合V最小的元素个数。
设Dis[i]为源点到达i集合中的元素个数
由题意可推出3个不等式:
Dis[bi] - Dis[ai-1] >= c[i];
Dis[i] - Dis[i-1] >= 0
Dis[i] - Dis[i-1] <= 1
根据上面三个关系建图,用SFPA求解最短路
#include
#include
#include
#include
#include
#include
#include
#include
#include