#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ll n, q;
cin>>n>>q;
vector<ll>pos(n);
for(ll i=0;i<n;i++){
cin>>pos[i];
}
vector<pair<ll,ll>>rangos;
rangos.push_back({0,0});
ll ml=0,rr=0;
ll suma=0;
for(ll i=0;i<q;i++){
ll w;
cin>>w;
suma+=w;
rr=max(suma,rr);
ml=min(suma,ml);
rangos.push_back({ml,rr});
}
vector<ll>amplitud(n,0LL);
amplitud[0]=-rangos[rangos.size()-1].first;
amplitud[n-1]+=rangos[rangos.size()-1].second;
for(ll i=0LL;i<n-1;i++){
ll l=0,r=rangos.size();
while(l<r){
ll mid=(l+r)/2;
if(pos[i]+rangos[mid].second>pos[i+1]+rangos[mid].first){
r=mid;
}
else{
l=mid+1;
}
}
cerr << "bs = " << l << endl;
ll dir=0;
if(l==rangos.size()){
amplitud[i]+=rangos[l-1].second;
amplitud[i+1]+=-rangos[l-1].first;
continue;
}
if(rangos[l].first<rangos[l-1].first)dir=-1;
else dir=1;
ll e=0;
if(dir==1){
amplitud[i+1]+=abs(min(0LL,rangos[l].first));
ll diff=pos[i+1]-abs(min(0LL,rangos[l].first));
diff=max(0LL,diff-pos[i]);
amplitud[i]+=diff;
}
else{
amplitud[i]+=abs(max(0LL,rangos[l].second));
ll diff=pos[i]+abs(max(0LL,rangos[l].second));
diff=max(0LL,pos[i+1]-diff);
amplitud[i+1]+=diff;
}
}
for(ll i=0;i<n;i++){
cout<<amplitud[i]<<"\n";
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:39:7: 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]
39 | if(l==rangos.size()){
| ~^~~~~~~~~~~~~~~
Main.cpp:46:6: warning: unused variable 'e' [-Wunused-variable]
46 | ll e=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
524 KB |
Output is correct |
4 |
Correct |
8 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
484 KB |
Output is correct |
7 |
Correct |
8 ms |
600 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
348 KB |
Output is correct |
10 |
Correct |
8 ms |
552 KB |
Output is correct |
11 |
Correct |
8 ms |
448 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
8 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
348 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
524 KB |
Output is correct |
4 |
Correct |
8 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
484 KB |
Output is correct |
7 |
Correct |
8 ms |
600 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
8 ms |
348 KB |
Output is correct |
10 |
Correct |
8 ms |
552 KB |
Output is correct |
11 |
Correct |
8 ms |
448 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
8 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
348 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
348 KB |
Output is correct |
20 |
Correct |
77 ms |
6880 KB |
Output is correct |
21 |
Correct |
62 ms |
6080 KB |
Output is correct |
22 |
Correct |
70 ms |
6336 KB |
Output is correct |
23 |
Correct |
71 ms |
6340 KB |
Output is correct |
24 |
Correct |
125 ms |
8120 KB |
Output is correct |
25 |
Correct |
805 ms |
14952 KB |
Output is correct |
26 |
Correct |
879 ms |
14012 KB |
Output is correct |
27 |
Correct |
820 ms |
13804 KB |
Output is correct |
28 |
Correct |
804 ms |
14224 KB |
Output is correct |
29 |
Correct |
806 ms |
13984 KB |
Output is correct |
30 |
Correct |
783 ms |
12988 KB |
Output is correct |
31 |
Correct |
754 ms |
12848 KB |
Output is correct |
32 |
Correct |
759 ms |
13488 KB |
Output is correct |
33 |
Correct |
80 ms |
1740 KB |
Output is correct |
34 |
Correct |
815 ms |
14752 KB |
Output is correct |
35 |
Correct |
837 ms |
14620 KB |
Output is correct |
36 |
Correct |
801 ms |
14436 KB |
Output is correct |
37 |
Correct |
807 ms |
14524 KB |
Output is correct |
38 |
Correct |
803 ms |
14116 KB |
Output is correct |
39 |
Correct |
815 ms |
14932 KB |
Output is correct |
40 |
Correct |
776 ms |
14800 KB |
Output is correct |
41 |
Correct |
73 ms |
8384 KB |
Output is correct |
42 |
Correct |
774 ms |
12640 KB |
Output is correct |
43 |
Correct |
796 ms |
14804 KB |
Output is correct |
44 |
Correct |
72 ms |
7360 KB |
Output is correct |
45 |
Correct |
771 ms |
14428 KB |
Output is correct |
46 |
Correct |
799 ms |
16128 KB |
Output is correct |
47 |
Correct |
817 ms |
15300 KB |
Output is correct |
48 |
Correct |
799 ms |
15388 KB |
Output is correct |