Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. 5 3
  2. 1 2 100
  3. 2 5 100
  4. 3 4 100
  5.  
  6. 200
  7.  
  8. 100 100 0 0 0
  9.  
  10. 100 200 100 100 100
  11.  
  12. 100 200 200 200 100
  13.  
  14. #include <bits/stdc++.h>
  15. #include <algorithm>
  16.  
  17. using namespace std;
  18.  
  19. int main() {
  20. int n, m;
  21. cin >> n >> m;
  22. vector<long long> v(n);
  23. for(int a0 = 0; a0 < m; a0++){
  24. int start, end, val;
  25. cin >> start >> end >> val;
  26. auto it_start = v.begin()+(start-1);
  27. auto it_end = v.begin()+(end);
  28. transform(it_start, it_end , it_start, [k](long long &x){return x+=k;});
  29. }
  30. cout << *max_element(v.begin(),v.end());
  31. return 0;
  32. }
  33.  
  34. #include <algorithm>
  35. #include <vector>
  36. #include <iostream>
  37.  
  38. int main() {
  39. int n; int m;
  40. std::cin >> n >> m;
  41. using val_type = long long;
  42. std::vector<val_type> v(n);
  43. while(m--){
  44. val_type start, end, val;
  45. std::cin >> start >> end >> val;
  46. auto it_start = v.begin()+(start-1);
  47. auto it_end = v.begin()+ end;
  48. *it_start += val;
  49. *it_end -= val;
  50. }
  51. val_type max{0};
  52. auto accumulate_max_val = [x=val_type(0),&max](val_type y) mutable {x+=y; if (x>max) max=x;};
  53. std::for_each(v.begin(),v.end(),accumulate_max_val);
  54. std::cout << max;
  55. return 0;
  56. }
  57.  
  58. #include <algorithm>
  59. #include <iostream>
  60. #include <map>
  61.  
  62. int main() {
  63. int n; int m;
  64. std::cin >> n >> m;
  65. using val_type = long long;
  66. std::map<int,val_type> map;
  67. while(m--){
  68. val_type start, end, val;
  69. std::cin >> start >> end >> val;
  70. map[start] += val;
  71. map[end+1] -= val;
  72. }
  73. val_type max{0};
  74. val_type partial_sum{0};
  75. for (const auto& el : map) {
  76. partial_sum += el.second;
  77. if (partial_sum > max) {
  78. max = partial_sum;
  79. }
  80. }
  81. std::cout << max;
  82. return 0;
  83. }
Add Comment
Please, Sign In to add comment