#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int32_t main() {
int n, q, s, t; cin >> n >> q >> s >> t;
vector<int> altitudes(n + 1), diffs(n);
for (int i=0;i<n+1;i++) {
cin >> altitudes[i];
}
ll ans = 0;
for (int i=0;i<n;i++) {
diffs[i] = altitudes[i+1] - altitudes[i];
if (diffs[i] < 0) {
ans -= t * diffs[i];
} else {
ans -= s * diffs[i];
}
}
int a, b, c;
for (int i=0;i<q;i++) {
cin >> a >> b >> c;
if (diffs[a - 1] > 0) {
diffs[a - 1] += c;
ans -= s * c;
if (diffs[a - 1] < 0) {
ans -= (-s + t) * diffs[a - 1];
}
} else {
diffs[a - 1] += c;
ans -= t * c;
if (diffs[a - 1] > 0) {
ans -= (s - t) * diffs[a - 1];
}
}
if (b != n) {
if (diffs[b] > 0) {
diffs[b] -= c;
ans += s * c;
if (diffs[b] < 0) {
ans += (s - t) * diffs[b];
}
} else {
diffs[b] -= c;
ans += t * c;
if (diffs[b] > 0) {
ans += (-s + t) * diffs[b];
}
}
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
492 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
318 ms |
4852 KB |
Output is correct |
2 |
Correct |
316 ms |
5572 KB |
Output is correct |
3 |
Correct |
307 ms |
6148 KB |
Output is correct |
4 |
Correct |
356 ms |
5204 KB |
Output is correct |
5 |
Correct |
330 ms |
5972 KB |
Output is correct |
6 |
Correct |
307 ms |
6736 KB |
Output is correct |
7 |
Correct |
340 ms |
6484 KB |
Output is correct |
8 |
Correct |
332 ms |
6484 KB |
Output is correct |
9 |
Correct |
331 ms |
6740 KB |
Output is correct |
10 |
Correct |
311 ms |
5360 KB |
Output is correct |
11 |
Correct |
326 ms |
6480 KB |
Output is correct |
12 |
Correct |
295 ms |
6740 KB |
Output is correct |
13 |
Correct |
298 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
492 KB |
Output is correct |
3 |
Correct |
3 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
318 ms |
4852 KB |
Output is correct |
23 |
Correct |
316 ms |
5572 KB |
Output is correct |
24 |
Correct |
307 ms |
6148 KB |
Output is correct |
25 |
Correct |
356 ms |
5204 KB |
Output is correct |
26 |
Correct |
330 ms |
5972 KB |
Output is correct |
27 |
Correct |
307 ms |
6736 KB |
Output is correct |
28 |
Correct |
340 ms |
6484 KB |
Output is correct |
29 |
Correct |
332 ms |
6484 KB |
Output is correct |
30 |
Correct |
331 ms |
6740 KB |
Output is correct |
31 |
Correct |
311 ms |
5360 KB |
Output is correct |
32 |
Correct |
326 ms |
6480 KB |
Output is correct |
33 |
Correct |
295 ms |
6740 KB |
Output is correct |
34 |
Correct |
298 ms |
7248 KB |
Output is correct |
35 |
Correct |
360 ms |
5132 KB |
Output is correct |
36 |
Correct |
336 ms |
6484 KB |
Output is correct |
37 |
Correct |
317 ms |
7488 KB |
Output is correct |
38 |
Correct |
316 ms |
6996 KB |
Output is correct |
39 |
Correct |
311 ms |
7108 KB |
Output is correct |
40 |
Correct |
315 ms |
7072 KB |
Output is correct |
41 |
Correct |
328 ms |
7108 KB |
Output is correct |
42 |
Correct |
315 ms |
6992 KB |
Output is correct |
43 |
Correct |
311 ms |
6452 KB |
Output is correct |
44 |
Correct |
317 ms |
6740 KB |
Output is correct |
45 |
Correct |
318 ms |
6344 KB |
Output is correct |
46 |
Correct |
330 ms |
7152 KB |
Output is correct |
47 |
Correct |
304 ms |
6988 KB |
Output is correct |
48 |
Correct |
319 ms |
7248 KB |
Output is correct |
49 |
Correct |
306 ms |
6228 KB |
Output is correct |
50 |
Correct |
291 ms |
7120 KB |
Output is correct |
51 |
Correct |
309 ms |
6960 KB |
Output is correct |
52 |
Correct |
320 ms |
7000 KB |
Output is correct |