#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
using namespace std;
const int N = 200005;
ll a[N],dp[4][N];
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i];
while(m--){
int l,r,k;
cin>>l>>r>>k;
for (int i=l;i<=r;i++)
a[i] += k;
vector <int> v;
v.clear();
for (int i=2;i<=n;i++)
v.pb(a[i-1] - a[i]);
for (int i=0;i<v.size();i++){
bool q=0;
if (i && v[i]*v[i-1] < 0) q=1;
if (i) dp[0][i] = max(dp[0][i - 1],dp[1][i-1]);
if (!q) dp[1][i] = dp[0][i] + abs(v[i]);
else dp[1][i] = dp[0][i - 1] + abs(v[i]);
}
cout<<max(dp[0][v.size()-1],dp[1][v.size()-1])<<"\n";
for (int i=0;i<=n;i++)
dp[0][i] = dp[1][i] = 0;
}
}
Compilation message
Main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main (){
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:30:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
72 ms |
468 KB |
Output is correct |
8 |
Correct |
72 ms |
720 KB |
Output is correct |
9 |
Correct |
70 ms |
468 KB |
Output is correct |
10 |
Correct |
70 ms |
472 KB |
Output is correct |
11 |
Correct |
73 ms |
460 KB |
Output is correct |
12 |
Correct |
66 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
72 ms |
468 KB |
Output is correct |
8 |
Correct |
72 ms |
720 KB |
Output is correct |
9 |
Correct |
70 ms |
468 KB |
Output is correct |
10 |
Correct |
70 ms |
472 KB |
Output is correct |
11 |
Correct |
73 ms |
460 KB |
Output is correct |
12 |
Correct |
66 ms |
476 KB |
Output is correct |
13 |
Execution timed out |
2093 ms |
10912 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |