# 题目分析

$$S=\sum_{i=1}^m e _ i v _ i = \sum_{i=1}^m e _ i \sum_{j=1}^i v _ j- v _ {j-1}=\sum _ {j=1} ^ m (v _ j- v _ {j-1})(\sum _ {i=j} ^ m e _ i)$$

# 代码

#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef double db;
const db eps=1e-9,inf=1e14;
const int N=2005,M=1000005;
int kas,n,m,S,T,tot;db sumsz;
int sz[32],L[32],R[32],v[32];db b[62];
int h[N],kh[N],lev[N],q[N],ne[M],to[M];db flow[M];

void add(int x,int y,db z) {
to[++tot]=y,ne[tot]=h[x],h[x]=tot,flow[tot]=z;
to[++tot]=x,ne[tot]=h[y],h[y]=tot,flow[tot]=0;
}
db dfs(int x,db liu) {
if(x==T) return liu;
db sum=0;
for(RI i=kh[x];i;kh[x]=ne[i],i=kh[x])
if(flow[i]>eps&&lev[to[i]]==lev[x]+1) {
db kl=dfs(to[i],min(liu-sum,flow[i]));
flow[i]-=kl,flow[i^1]+=kl,sum+=kl;
if(fabs(liu-sum)<eps) return sum;
}
lev[x]=-1;return sum;
}
int bfs() {
for(RI i=1;i<=T;++i) lev[i]=0;
int he=1,ta=1;lev[S]=1,q[1]=S;
while(he<=ta) {
int x=q[he];++he;
if(x==T) return 1;
for(RI i=h[x];i;i=ne[i])
if(flow[i]>eps&&!lev[to[i]])
lev[to[i]]=lev[x]+1,q[++ta]=to[i];
}
return 0;
}
db dinic() {
db re=0;
while(bfs()) {
for(RI i=1;i<=T;++i) kh[i]=h[i];
re+=dfs(S,inf);
}
return re;
}

int check(db tim) {
S=n+n*m*2+1,T=n+n*m*2+2;
tot=1;for(RI i=1;i<=T;++i) h[i]=0;
sort(b+1,b+1+n+n);
for(RI i=2;i<=n+n;++i) {
db t=b[i]-b[i-1];
if(t<eps) continue;
for(RI j=1;j<=m;++j) {
int kl=n+(i-1)*m+j;
for(RI k=1;k<=n;++k)
}
}
return fabs(sumsz-dinic())<eps;
}
bool cmp(int x,int y) {return x>y;}
int main()
{
scanf("%d",&kas);
while(kas--) {
scanf("%d%d",&n,&m);sumsz=0;
for(RI i=1;i<=n;++i) scanf("%d%d%d",&sz[i],&L[i],&R[i]),sumsz+=sz[i];
for(RI i=1;i<=m;++i) scanf("%d",&v[i]);
sort(v+1,v+1+m,cmp);
db l=0,r=sumsz/v[1];
for(RI i=1;i<m;++i) v[i]=v[i]-v[i+1];
while(r-l>1e-5) {
db mid=(l+r)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.5lf\n",l);
}
return 0;
}