正解:线性规划。
直接套单纯形的板子,因为所约束条件都是>=号,且目标函数为最小值,所以考虑对偶转换,转置一下原矩阵就好了。
1 //It is made by wfj_2048~ 2 #include <algorithm> 3 #include <iostream> 4 #include <complex> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cstdio> 8 #include <vector> 9 #include <cmath> 10 #include <queue> 11 #include <stack> 12 #include <map> 13 #include <set> 14 #define inf (1e15) 15 #define eps (1e-12) 16 #define il inline 17 #define RG register 18 #define ll long long 19 20 using namespace std; 21 22 double a[1010][10010]; 23 int b[10010],n,m; 24 25 il int gi(){ 26 RG int x=0,q=1; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar(); 27 if (ch=='-') q=-1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; 28 } 29 30 il void pivot(RG int l,RG int e){ 31 RG double k=a[l][e]; a[l][e]=1; 32 for (RG int i=0;i<=n;++i) a[l][i]/=k; RG int len=0; 33 for (RG int i=0;i<=n;++i) if (fabs(a[l][i])>eps) b[++len]=i; 34 for (RG int i=0;i<=m;++i) 35 if (i!=l && fabs(a[i][e])>eps){ 36 k=a[i][e],a[i][e]=0; 37 for (RG int j=1;j<=len;++j) a[i][b[j]]-=k*a[l][b[j]]; 38 } 39 return; 40 } 41 42 il double simplex(){ 43 while (1){ 44 RG int l,e; for (e=1;e<=n;++e) if (a[0][e]>eps) break; 45 if (e==n+1) return -a[0][0]; RG double tmp=inf; 46 for (RG int i=1;i<=m;++i) 47 if (a[i][e]>eps && tmp>a[i][0]/a[i][e]) tmp=a[i][0]/a[i][e],l=i; 48 if (tmp==inf) return inf; pivot(l,e); 49 } 50 } 51 52 il void work(){ 53 m=gi(),n=gi(); RG int l,r,d; 54 for (RG int i=1;i<=m;++i) a[i][0]=gi(); 55 for (RG int i=1;i<=n;++i){ 56 l=gi(),r=gi(),d=gi(); a[0][i]=d; 57 for (RG int j=l;j<=r;++j) a[j][i]=1; 58 } 59 printf("%lld ",(ll)(simplex()+0.5)); return; 60 } 61 62 int main(){ 63 work(); 64 return 0; 65 }