//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo it[200001];
llo mi[200001];
llo ma[200001];
llo n,q;
vector<llo> ss;
bool check(llo mid,llo i){
if(mid==0){
return false;
}
if(mi[q-1]>0){
return false;
}
if(-mi[q-1]<mid){
return false;
}
//return true;
llo ind=q-1;
for(llo j=19;j>=0;j--){
if(ind-(1<<j)>=0){
if(mi[ind-(1<<j)]<=0 and (-mi[ind-(1<<j)])>=mid){
ind-=(1<<j);
}
}
}
if(i==0){
return true;
}
if((mid)>it[i]-it[i-1]){
return false;
}
//cout<<i<<":"<<mid<<endl;
//return true;
if(ind==0){
return true;
}
if(ma[ind-1]+it[i-1]<=it[i]-mid){
return true;
}
return false;
}
bool check2(llo mid,llo i){
if(mid==0){
return false;
}
if(ma[q-1]<0){
return false;
}
if(ma[q-1]<mid){
return false;
}
//return true;
llo ind=q-1;
for(llo j=19;j>=0;j--){
if(ind-(1<<j)>=0){
if((ma[ind-(1<<j)])>=mid){
ind-=(1<<j);
}
}
}
/* if(i==0){
cout<<mid<<"::"<<ind<<endl;
}*/
/*if(mid==5 and i==0){
cout<<11<<"::"<<endl;
}*/
if(i==n-1){
return true;
}
if((mid)>it[i+1]-it[i]){
return false;
}
//cout<<i<<":"<<mid<<endl;
//return true;
if(ind==0){
return true;
}
if(mi[ind-1]+it[i+1]>=it[i]+mid){
return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q;
for(llo i=0;i<n;i++){
cin>>it[i];
}
/*llo q;
cin>>q;*/
llo su=0;
for(llo i=0;i<q;i++){
llo aa;
cin>>aa;
su+=aa;
ss.pb(su);
}
mi[0]=ss[0];
ma[0]=ss[0];
for(llo i=1;i<ss.size();i++){
mi[i]=min(mi[i-1],ss[i]);
ma[i]=max(ma[i-1],ss[i]);
}
/* for(llo i=0;i<q;i++){
cout<<mi[i]<<":";
}
cout<<endl;*/
for(llo i=0;i<n;i++){
llo low=0;
llo high=1e18;
while(low<high-1){
llo mid=(low+high)/2;
if(check(mid,i)){
low=mid;
}
else{
high=mid;
}
}
llo ind=low;
if(check(high,i)){
ind=max(ind,high);
}
//cout<<ind<<":"<<endl;
low=0;
high=1e18;
while(low<high-1){
llo mid=(low+high)/2;
if(check2(mid,i)){
low=mid;
}
else{
high=mid;
}
}
llo ind2=low;
if(check2(high,i)){
ind2=max(ind2,high);
}
cout<<ind+ind2<<endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:115:15: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
115 | for(llo i=1;i<ss.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
8 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
5 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
9 ms |
492 KB |
Output is correct |
16 |
Correct |
8 ms |
492 KB |
Output is correct |
17 |
Correct |
8 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
8 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
5 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
4 ms |
492 KB |
Output is correct |
10 |
Correct |
3 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
9 ms |
492 KB |
Output is correct |
16 |
Correct |
8 ms |
492 KB |
Output is correct |
17 |
Correct |
8 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
492 KB |
Output is correct |
20 |
Correct |
33 ms |
5220 KB |
Output is correct |
21 |
Correct |
32 ms |
5220 KB |
Output is correct |
22 |
Correct |
32 ms |
5220 KB |
Output is correct |
23 |
Correct |
46 ms |
5352 KB |
Output is correct |
24 |
Correct |
191 ms |
5476 KB |
Output is correct |
25 |
Correct |
1455 ms |
8804 KB |
Output is correct |
26 |
Correct |
1518 ms |
8548 KB |
Output is correct |
27 |
Correct |
1340 ms |
8164 KB |
Output is correct |
28 |
Correct |
1330 ms |
8292 KB |
Output is correct |
29 |
Correct |
1297 ms |
7984 KB |
Output is correct |
30 |
Correct |
827 ms |
7524 KB |
Output is correct |
31 |
Correct |
312 ms |
7112 KB |
Output is correct |
32 |
Correct |
159 ms |
7140 KB |
Output is correct |
33 |
Correct |
99 ms |
1264 KB |
Output is correct |
34 |
Correct |
1746 ms |
8384 KB |
Output is correct |
35 |
Correct |
1423 ms |
8164 KB |
Output is correct |
36 |
Correct |
1522 ms |
8304 KB |
Output is correct |
37 |
Correct |
1446 ms |
8220 KB |
Output is correct |
38 |
Correct |
1382 ms |
8116 KB |
Output is correct |
39 |
Correct |
1458 ms |
8124 KB |
Output is correct |
40 |
Correct |
1159 ms |
8164 KB |
Output is correct |
41 |
Correct |
134 ms |
5220 KB |
Output is correct |
42 |
Correct |
134 ms |
7092 KB |
Output is correct |
43 |
Correct |
1169 ms |
8580 KB |
Output is correct |
44 |
Correct |
43 ms |
5220 KB |
Output is correct |
45 |
Correct |
717 ms |
8224 KB |
Output is correct |
46 |
Correct |
892 ms |
8580 KB |
Output is correct |
47 |
Correct |
1164 ms |
8572 KB |
Output is correct |
48 |
Correct |
748 ms |
8420 KB |
Output is correct |