#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
void solve(){
int n;
cin >> n;
int q;
cin >> q;
ll arr[n];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
vector<ll> v;
ll mx[q] , mn[q] , cur = 0;
mx[0] = mn[0] = 0;
for(int i = 0; i < q; i++){
ll x;
cin >> x;
cur += x;
if(i != 0){
mn[i] = min(mn[i-1] , cur);
mx[i] = max(mx[i-1] , cur);
}
else {
mx[i] = max(mx[i] , cur);
mn[i] = min(mn[i] , cur);
}
v.pb(mx[i] - mn[i]);
}
ll l[n] , r[n];
l[0] = abs(mn[q-1]) , r[n-1] = mx[q-1];
for(int i = 0; i < n-1; i++){
int p = upper_bound(all(v) , arr[i + 1] - arr[i]) - v.begin();
//cout << p << ' ';
if(p == (int)v.size()){
p--;
r[i] = mx[p];
l[i + 1] = abs(mn[p]);
}
else if(p == 0){
r[i] = l[i + 1] = 0;
if(mx[p] > 0){
r[i] = arr[i + 1] - arr[i];
}
else {
l[i + 1] = arr[i + 1] - arr[i];
}
}
else {
r[i] = mx[p-1];
l[i + 1] = abs(mn[p-1]);
ll rem = arr[i + 1] - arr[i];
rem -= mx[p-1] + abs(mn[p-1]);
if(mx[p] > mx[p-1]){
r[i] += rem;
}
else l[i + 1] += rem;
}
}
//cout << '\n';
for(int i = 0; i < n; i++){
//cout << l[i] << ' ' << r[i] << ' ';
cout << l[i] + r[i] << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
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 |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 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 |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
360 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
29 ms |
7240 KB |
Output is correct |
21 |
Correct |
25 ms |
7068 KB |
Output is correct |
22 |
Correct |
25 ms |
6984 KB |
Output is correct |
23 |
Correct |
22 ms |
6856 KB |
Output is correct |
24 |
Correct |
30 ms |
7312 KB |
Output is correct |
25 |
Correct |
93 ms |
15148 KB |
Output is correct |
26 |
Correct |
92 ms |
15032 KB |
Output is correct |
27 |
Correct |
104 ms |
14636 KB |
Output is correct |
28 |
Correct |
90 ms |
14780 KB |
Output is correct |
29 |
Correct |
90 ms |
14356 KB |
Output is correct |
30 |
Correct |
81 ms |
13752 KB |
Output is correct |
31 |
Correct |
65 ms |
13116 KB |
Output is correct |
32 |
Correct |
68 ms |
13292 KB |
Output is correct |
33 |
Correct |
9 ms |
1872 KB |
Output is correct |
34 |
Correct |
96 ms |
15416 KB |
Output is correct |
35 |
Correct |
95 ms |
14892 KB |
Output is correct |
36 |
Correct |
93 ms |
15144 KB |
Output is correct |
37 |
Correct |
92 ms |
14776 KB |
Output is correct |
38 |
Correct |
91 ms |
14752 KB |
Output is correct |
39 |
Correct |
87 ms |
14904 KB |
Output is correct |
40 |
Correct |
72 ms |
14892 KB |
Output is correct |
41 |
Correct |
29 ms |
7776 KB |
Output is correct |
42 |
Correct |
59 ms |
13356 KB |
Output is correct |
43 |
Correct |
82 ms |
16544 KB |
Output is correct |
44 |
Correct |
29 ms |
7748 KB |
Output is correct |
45 |
Correct |
63 ms |
14796 KB |
Output is correct |
46 |
Correct |
78 ms |
16768 KB |
Output is correct |
47 |
Correct |
81 ms |
16940 KB |
Output is correct |
48 |
Correct |
77 ms |
17080 KB |
Output is correct |