fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MaxN=2e5;
  5. int add[MaxN+1]={};
  6. int N;//start end value
  7. int M;
  8. long ans=0;
  9. int main() {
  10. cin>>N>>M;
  11. int work[N]={};
  12. int ability[N]={};
  13. for(int n=0;n<M;n++){
  14. int v,s,e;
  15. cin>>s>>e>>v;
  16. add[s]+=v;
  17. add[e+1]-=v;
  18. }
  19. int now=0;
  20. for(int n=1;n<=N;n++){
  21. now+=add[n];
  22. work[n-1]=now;
  23. }
  24. for(int n=0;n<N;n++)
  25. cin>>ability[n];
  26. sort(work,work+N);
  27. sort(ability,ability+N);
  28. for(int n=0;n<N;n++){
  29. ans+=work[N-1-n]*ability[n];
  30. }
  31. cout<<ans<<endl;
  32. for(int n=0;n<N;n++){
  33. cout<<work[n]<<" ";
  34. }
  35. cout<<endl;
  36. for(int n=0;n<N;n++){
  37. cout<<ability[n]<<" ";
  38. }
  39.  
  40. }
  41.  
Success #stdin #stdout 0.01s 5296KB
stdin
10 3
2 5 6
3 6 4
7 8 1
1 2 3 4 5 6 7 8 9 10
stdout
117
0 0 0 1 1 4 6 10 10 10 
1 2 3 4 5 6 7 8 9 10