#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,q;
cin>>n>>q;
vll arr;
arr.pb(-INF);
vector<ii>exo;
f(i,0,n){
ll a;
cin>>a;
arr.pb(a);
}
arr.pb(INF);
f(i,0,n+1){
exo.pb(ii(arr[i+1] - arr[i],i));
}
ll ans[n+1] = {0};
ll cur = 0;
ll mini = 0,maxi = 0;
sort(all(exo));
reverse(all(exo));
while(q--){
ll w;
cin>>w;
cur += w;
maxi = max(maxi,cur);
mini = min(mini,cur);
while(!exo.empty() && exo.back().F <= abs(mini) + maxi){
ll c = abs(mini) + maxi - exo.back().F;
ll i = exo.back().S;
if(maxi == cur){
ans[i] += maxi - c;
ans[i+1] += abs(mini);
}
else{
ans[i] += maxi;
ans[i+1] += abs(mini) - c;
}
exo.pop_back();
}
}
while(!exo.empty()){
ll i = exo.back().S;
exo.pop_back();
ans[i] += maxi;
ans[i+1] += abs(mini);
}
f(i,1,n+1){
cout<<ans[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
27 ms |
2348 KB |
Output is correct |
21 |
Correct |
35 ms |
2224 KB |
Output is correct |
22 |
Correct |
25 ms |
1996 KB |
Output is correct |
23 |
Correct |
20 ms |
1988 KB |
Output is correct |
24 |
Correct |
25 ms |
2760 KB |
Output is correct |
25 |
Correct |
83 ms |
11940 KB |
Output is correct |
26 |
Correct |
103 ms |
11956 KB |
Output is correct |
27 |
Correct |
79 ms |
11528 KB |
Output is correct |
28 |
Correct |
83 ms |
11696 KB |
Output is correct |
29 |
Correct |
87 ms |
11296 KB |
Output is correct |
30 |
Correct |
80 ms |
10684 KB |
Output is correct |
31 |
Correct |
76 ms |
9996 KB |
Output is correct |
32 |
Correct |
86 ms |
10316 KB |
Output is correct |
33 |
Correct |
10 ms |
1600 KB |
Output is correct |
34 |
Correct |
87 ms |
12396 KB |
Output is correct |
35 |
Correct |
89 ms |
11700 KB |
Output is correct |
36 |
Correct |
104 ms |
12032 KB |
Output is correct |
37 |
Correct |
89 ms |
11736 KB |
Output is correct |
38 |
Correct |
86 ms |
11624 KB |
Output is correct |
39 |
Correct |
86 ms |
11848 KB |
Output is correct |
40 |
Correct |
94 ms |
11904 KB |
Output is correct |
41 |
Correct |
29 ms |
3040 KB |
Output is correct |
42 |
Correct |
81 ms |
10160 KB |
Output is correct |
43 |
Correct |
103 ms |
13536 KB |
Output is correct |
44 |
Correct |
30 ms |
2852 KB |
Output is correct |
45 |
Correct |
82 ms |
11728 KB |
Output is correct |
46 |
Correct |
105 ms |
13624 KB |
Output is correct |
47 |
Correct |
105 ms |
13860 KB |
Output is correct |
48 |
Correct |
87 ms |
13892 KB |
Output is correct |