BACKGROUND Background
Stupid: small watermelon, small watermelon ~
Lu renjia: No, this watermelon is big ......
Stupid: That ...... Big watermelon, big watermelon ~
Passerby A: It's time to change ......
Stupid: Watermelon ~ Cute watermelon ~
Description
Stupid planting of a watermelon land, but the planting range of this watermelon land is a straight line ......
After some research, he came to M conclusion that the M conclusion can make him get the most watermelon.
The stupid conclusion is as follows:
At least t watermelon should be planted from B to E, and the harvest in this range can be maximized.
He doesn't want to work so hard, so he wants to plant as few watermelons as possible and satisfy every conclusion.
Input Format
The first line of two numbers n, m (0 <n <= 3000, 0 <= m <=), indicating the length of the stupid watermelon land N, stupid to draw M conclusions.
Next, the m rows indicate the stupid M conclusions. Each row contains three numbers: B, E, T (1 <= B <= e <= n, 0 <= T <= e-B + 1 ).
Output Format
Output how many watermelons are stupid to plant at least.
[Reference Program ]:
# Include <cstring>
# Include <cstdio>
# Include <iostream>
Using namespace STD;
Struct Node
{
Int B, E, T;
} A [3010];
Int f [5010], C [5010];
Int n, m;
Int CMP (const void * s, const void * t)
{
Node I = * (node *) s, j = * (node *) T;
Return I. e-j.e;
}
Int lowbit (int x)
{
Return x ^ (X & (x-1 ));
}
Void modify (int x)
{
While (x <= N)
{
C [x] ++;
X + = lowbit (X );
}
}
Int getsum (int x)
{
Int sum = 0;
While (X)
{
Sum + = C [x];
X-= lowbit (X );
}
Return sum;
}
Int main ()
{
Scanf ("% d", & N, & M );
For (INT I = 1; I <= m; I ++)
Scanf ("% d", & A [I]. B, & A [I]. E, & A [I]. t );
Qsort (a + 1, m, sizeof (node), CMP );
Memset (C, 0, sizeof (c ));
Memset (F, 0, sizeof (f ));
Int need, ANS = 0;
For (INT I = 1; I <= m; I ++)
{// Currently, this conclusion requires more than one watermelon to be planted.
Need = A [I]. T-(getsum (A [I]. e)-getsum (A [I]. b-1 ));
For (Int J = A [I]. E; j> = A [I]. B; j --)
{
If (need <= 0) break;
If (! F [J])
{
F [J] = 1; need --;
Modify (j); ans ++;
}
}
}
Printf ("% d/N", ANS );
Return 0;
}