solved hackerrank's array manipulation

Signed-off-by: ayham <altffour@protonmail.com>
This commit is contained in:
ayham 2021-05-13 09:14:14 +03:00
parent 08a077d715
commit 1091b6727a
No known key found for this signature in database
GPG Key ID: 81D38F7122AFCC94
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll max_num = -1, height = 0;
ll n, m;
ll a=0, b=0, k=0;
cin.sync_with_stdio(false);
cin >> n >> m;
vector<ll> *arr = new vector<ll>(n+1);
fill((*arr).begin(), (*arr).end(), 0);
while (m--) {
cin >> a >> b >> k;
(*arr)[a] += k;
if ((b+1) <= n) (*arr)[b+1] -= k;
}
for (int i = 1; i <= n; i++) {
height = height + (*arr)[i];
if (max_num < height) max_num = height;
}
cout << max_num << endl;
return 0;
}