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