Transmission Door :
Have 2∗n time to fry a two sides of meat, give you k can be flipped interval [Li,ri] [L I, R I] [L_i,r_i], can flip any time within the interval to ensure that the interval does not intersect
Ask if there is a legal solution that makes both sides just fry for n minutes and ask for the minimum number of flips
n<=100000,k<=100 Solution:
Consider a simple DP.
F[I][J] f [i] [j] F[i][j] represents the first I-second, the minimum number of flips required to bake a surface that is not currently roasted
Transfer f[i][j]=f[i−1][j],f[i][j]=f[i−1][i−j]+1 F [i] [j] = f [i−1] [j], F [i] [j] = f [i−1] [i−j] + 1 F I [J]=f[i-1][j],f[i][j]=f[i-1][i-j]+1
But this is O (n2) O (n 2) O (n^2), which needs to be optimized
Notice that the second shift only happens in this k interval.
Then we can change the state:
F[I][J] f [i] [j] F[i][j] represents the forward Ri R i r_i seconds, the minimum number of flips required for the current not baked surface to be roasted for j seconds
At the same time we found that the meat of each interval was flipped up to 2 times, so we could split it up and turn it over two times to discuss
The transfer is
F[i][j]=mink≤ri−lik=0 (f[i−1][j−k]) +2 f [i] [j] = m i n k = 0 K≤r i−l i (f [i−1] [j−k]) + 2 f[i][j]=min_{ K=0}^{k≤r_i-l_i} (F[i-1][j-k]) +2,