#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
#define int ll
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
ll x[N];
bool L[N], R[N];
int res[N];
void solve(int tc) {
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i ++) {
cin >> x[i];
}
vector<pair<int,int>> vec;
for(int i = 1; i < n; i ++) {
vec.push_back({x[i+1]-x[i], i});
}
sort(all(vec));
int mx = 0, mn = 0, cur = 0;
int it = 0;
for(int i = 1; i <= q; i ++) {
ll w;
cin >> w;
int c1 = cur, mx1 = mx, mn1 = mn;
cur += w;
mx = max(mx, cur);
mn = min(mn , cur);
while(it < vec.size() && mx-mn >= vec[it].F) {
res[vec[it].S] += mx1;
res[vec[it].S+1] -= mn1;
if(w > 0) {
res[vec[it].S] += vec[it].F-mx1+mn1;
}
else {
res[vec[it].S+1] += vec[it].F-mx1+mn1;
}
R[vec[it].S] = 1;
L[vec[it].S+1] = 1;
it ++;
}
}
for(int i = 1; i <= n; i ++) {
if(L[i] == 0) res[i] += -mn;
if(R[i] == 0) res[i] += mx;
cout << res[i] << '\n';
}
}
/*
*/
main() {
ios;
int tt = 1 , tc = 0;
// cin >> tt;
while(tt --) {
solve(++tc);
}
return 0;
}
Compilation message
Main.cpp: In function 'void solve(ll)':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | while(it < vec.size() && mx-mn >= vec[it].F) {
| ~~~^~~~~~~~~~~~
Main.cpp:36:7: warning: unused variable 'c1' [-Wunused-variable]
36 | int c1 = cur, mx1 = mx, mn1 = mn;
| ^~
Main.cpp: At global scope:
Main.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
24 ms |
1584 KB |
Output is correct |
21 |
Correct |
28 ms |
1612 KB |
Output is correct |
22 |
Correct |
23 ms |
1652 KB |
Output is correct |
23 |
Correct |
26 ms |
1752 KB |
Output is correct |
24 |
Correct |
38 ms |
2572 KB |
Output is correct |
25 |
Correct |
84 ms |
9976 KB |
Output is correct |
26 |
Correct |
86 ms |
9932 KB |
Output is correct |
27 |
Correct |
103 ms |
9692 KB |
Output is correct |
28 |
Correct |
88 ms |
9788 KB |
Output is correct |
29 |
Correct |
91 ms |
9632 KB |
Output is correct |
30 |
Correct |
89 ms |
9148 KB |
Output is correct |
31 |
Correct |
78 ms |
8808 KB |
Output is correct |
32 |
Correct |
67 ms |
8756 KB |
Output is correct |
33 |
Correct |
12 ms |
1620 KB |
Output is correct |
34 |
Correct |
94 ms |
9916 KB |
Output is correct |
35 |
Correct |
80 ms |
9772 KB |
Output is correct |
36 |
Correct |
79 ms |
9908 KB |
Output is correct |
37 |
Correct |
83 ms |
9800 KB |
Output is correct |
38 |
Correct |
100 ms |
9760 KB |
Output is correct |
39 |
Correct |
92 ms |
9792 KB |
Output is correct |
40 |
Correct |
83 ms |
9780 KB |
Output is correct |
41 |
Correct |
33 ms |
1552 KB |
Output is correct |
42 |
Correct |
85 ms |
8384 KB |
Output is correct |
43 |
Correct |
107 ms |
10068 KB |
Output is correct |
44 |
Correct |
31 ms |
1736 KB |
Output is correct |
45 |
Correct |
83 ms |
9384 KB |
Output is correct |
46 |
Correct |
110 ms |
10020 KB |
Output is correct |
47 |
Correct |
83 ms |
10044 KB |
Output is correct |
48 |
Correct |
82 ms |
10008 KB |
Output is correct |