真不是我水博客但是它就是那么简单,和它们一模一样
直接套单纯形法的板子
#include<cstdio>
#include<cmath>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=1005,M=10005;
const double EPS=1e-8;
int n,m,tp,l,r; double a[N][M];
namespace SM //Simplex Method
{
int id[N+M];
inline void pivot(CI l,CI e)
{
RI i,j; swap(id[n+l],id[e]); double t=a[l][e];
for (a[l][e]=1,i=0;i<=n;++i) a[l][i]/=t;
for (i=0;i<=m;++i) if (i!=l&&fabs(a[i][e])>EPS)
for (t=a[i][e],a[i][e]=j=0;j<=n;++j) a[i][j]-=t*a[l][j];
}
inline void simplex(void)
{
for (;;)
{
RI i; int l=0,e=0; double mi=1e9;
for (i=1;i<=n;++i) if (a[0][i]>EPS) { e=i; break; } if (!e) break;
for (i=1;i<=m;++i) if (a[i][e]>EPS&&a[i][0]/a[i][e]<mi) mi=a[i][0]/a[i][e],l=i; pivot(l,e);
}
}
};
int main()
{
RI i,j; for (scanf("%d%d",&m,&n),i=1;i<=m;++i) scanf("%lf",&a[i][0]);
for (i=1;i<=n;++i) for (scanf("%d%d%lf",&l,&r,&a[0][i]),j=l;j<=r;++j) a[j][i]=1;
return SM::simplex(),printf("%d",(int)(-a[0][0]+0.5)),0;
}