fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MaxN=2e5+1;
  4. int N,M;
  5. long L[MaxN]={},R[MaxN]={},W[MaxN]={},T[MaxN]={};
  6. long Line[MaxN]={};
  7. long add[MaxN]={};
  8. long comp(long lhs,long rhs){
  9. return lhs>rhs;
  10. }
  11. int main(){
  12. cin>>N>>M;
  13. for(int m=0;m<M;m++){
  14. cin>>L[m]>>R[m]>>W[m];
  15. R[m]++;
  16. }
  17. for(int n=0;n<N;n++){
  18. cin>>T[n];
  19. }
  20. for(int m=0;m<=M;m++){
  21. add[L[m]]+=W[m];
  22. add[R[m]]-=W[m];
  23. }
  24. long now=0;
  25. for(int n=0;n<=N;n++){
  26. now+=add[n];
  27. Line[n]=now;
  28. }
  29. sort(Line,Line+N+1,comp);
  30. sort(T,T+N);
  31. long ans=0;
  32. for(int n=0;n<=N;n++){
  33. ans+=Line[n]*T[n];
  34. }
  35. cout<<ans;
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 11736KB
stdin
10 3
2 5 6
3 6 4
7 8 1
10 9 8 7 6 5 4 3 2 1
stdout
117