-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_16.cpp
More file actions
39 lines (30 loc) · 902 Bytes
/
Copy pathLab_16.cpp
File metadata and controls
39 lines (30 loc) · 902 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
37
38
39
#include <iostream>
#include <vector>
#include <algorithm>
long long solve() {
int arraySize, queryCount;
std::cin >> arraySize >> queryCount;
std::vector<long long> diffArray(arraySize + 2, 0);
for (int i = 0; i < queryCount; ++i) {
int a, b, k;
std::cin >> a >> b >> k;
diffArray[a] += k;
if (b + 1 <= arraySize) {
diffArray[b + 1] -= k;
}
}
long long currentMax = 0;
long long runningSum = 0;
for (int i = 1; i <= arraySize; ++i) {
runningSum += diffArray[i];
if (runningSum > currentMax) {
currentMax = runningSum;
}
}
return currentMax;
}
int main() {
std::cout << sol
ve() << std::endl;
return 0;
}