Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5 3
- 1 2 100
- 2 5 100
- 3 4 100
- 200
- 100 100 0 0 0
- 100 200 100 100 100
- 100 200 200 200 100
- #include <bits/stdc++.h>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- vector<long long> v(n);
- for(int a0 = 0; a0 < m; a0++){
- int start, end, val;
- cin >> start >> end >> val;
- auto it_start = v.begin()+(start-1);
- auto it_end = v.begin()+(end);
- transform(it_start, it_end , it_start, [k](long long &x){return x+=k;});
- }
- cout << *max_element(v.begin(),v.end());
- return 0;
- }
- #include <algorithm>
- #include <vector>
- #include <iostream>
- int main() {
- int n; int m;
- std::cin >> n >> m;
- using val_type = long long;
- std::vector<val_type> v(n);
- while(m--){
- val_type start, end, val;
- std::cin >> start >> end >> val;
- auto it_start = v.begin()+(start-1);
- auto it_end = v.begin()+ end;
- *it_start += val;
- *it_end -= val;
- }
- val_type max{0};
- auto accumulate_max_val = [x=val_type(0),&max](val_type y) mutable {x+=y; if (x>max) max=x;};
- std::for_each(v.begin(),v.end(),accumulate_max_val);
- std::cout << max;
- return 0;
- }
- #include <algorithm>
- #include <iostream>
- #include <map>
- int main() {
- int n; int m;
- std::cin >> n >> m;
- using val_type = long long;
- std::map<int,val_type> map;
- while(m--){
- val_type start, end, val;
- std::cin >> start >> end >> val;
- map[start] += val;
- map[end+1] -= val;
- }
- val_type max{0};
- val_type partial_sum{0};
- for (const auto& el : map) {
- partial_sum += el.second;
- if (partial_sum > max) {
- max = partial_sum;
- }
- }
- std::cout << max;
- return 0;
- }
Add Comment
Please, Sign In to add comment