Submission #967306

#TimeUsernameProblemLanguageResultExecution timeMemory
967306Math4Life2020Sjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms348 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int main() { long long N,Q; cin >> N >> Q; long long a[N]; for (long long i=0;i<N;i++) { cin >> a[i]; } //solve: for (long long q=0;q<Q;q++) { long long l,r,x; cin >> l >> r >> x; l--; r--; for (long long i=l;i<=r;i++) { a[i] += x; } long long val = 0; for (long long i=1;i<N;i++) { val += abs(a[i]-a[i-1]); if (i<(N-1)) { if (!(((a[i-1]<a[i])&&(a[i]<a[i+1]))||((a[i-1]>a[i])&&(a[i]>a[i+1])))) { val -= min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1])); } } } cout << val <<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...