forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH0001.cpp
More file actions
36 lines (32 loc) · 747 Bytes
/
H0001.cpp
File metadata and controls
36 lines (32 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Problem Code: https://www.hackerrank.com/challenges/crush/problem
*/
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
long long arrayManipulation(int n, vector< tuple<int, int, int> > &queries) {
int a, b, k;
vector<long long> arr(n);
for (int i = 0; i < queries.size(); i++) {
tie(a, b, k) = queries[i];
arr[a - 1] += k;
arr[b] -= k;
}
for (int i = 1; i < n; i++)
arr[i] += arr[i - 1];
return *max_element(arr.begin(), arr.end());
}
int main() {
int n, m;
cin >> n >> m;
vector< tuple<int, int, int> > queries(m);
for (int i = 0; i < m; i++) {
int a, b, k;
cin >> a >> b >> k;
queries[i] = make_tuple(a, b, k);
}
cout << arrayManipulation(n, queries);
return 0;
}