#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FFOR(i,a,b,c) for(int i=(a);(c)>0?i<=(b):i>=(b);i+=(c))
#define FOOR(i,a,b) FFOR(i,a,(b)-1,1)
#define ROOF(i,a,b) FFOR(i,(b)-1,a,-1)
#define FOR(i,n) FOOR(i,0,n)
#define ROF(i,n) ROOF(i,0,n)
#define FORR(x,v) for(auto &x:v)
#define vc vector
#define sz(v) (int)((v).size())
#define bg begin()
#define en end()
#define em empty()
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define ppb pop_back()
#define eb emplace_back
#define bk back()
#define fr front()
#define pp pop()
#define all(v) (v).begin(),(v).end()
#define lla(v) (v).rbegin(),(v).rend()
#define f first
#define s second
struct node {
ll sum, pre, suf, best;
node(){sum=pre=suf=best=0;}
node(ll a){sum=a;pre=suf=best=min(a,0ll);}
};
node operator+(const node &a, const node &b) {
node c;
c.sum=a.sum+b.sum;
c.pre=min(a.pre,a.sum+b.pre);
c.suf=min(b.suf,b.sum+a.suf);
c.best=min({a.best,b.best,a.suf+b.pre});
return c;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,D;
cin>>N>>M>>D;
if(M<=10){
vc<int> a(N);
FORR(x,a)cin>>x;
FOR(i,M){
int b;
cin>>b;
a.pb(b);
sort(all(a));
ll s=0,ans=0;
FOOR(j,1,sz(a)){
ll k=a[j]-a[j-1]-D;
s=min(k,s+k);
ans=min(ans,s);
}
ans=-ans;
if(ans%2==1){
cout<<ans/2<<"."<<5<<" ";
}else{
cout<<ans/2<<" ";
}
}
return 0;
}
vc<int> b(M);
vc<pair<int,int>> p(M);
FOR(i,M){
cin>>b[i];
p[i]={b[i],i};
}
sort(all(p));
vc<int> pos(M);
FOR(i,M) pos[p[i].s]=i;
vc<node> st(2*M);
auto upd = [&](int i, ll v) {
for(st[i+=M]=v;i/=2;) {
st[i]=st[i*2]+st[i*2+1];
}
};
set<int> s;
FOR(i,M){
auto it=s.ub(pos[i]);
if(it!=s.bg){
upd(pos[i],b[i]-p[*prev(it)].f-D);
}
if(it!=s.en){
upd(*it,p[*it].f-b[i]-D);
}
s.insert(pos[i]);
node u,v;
for(int l=M,r=2*M;l<r;l/=2,r/=2){
if(l&1) u=u+st[l++];
if(r&1) v=st[--r]+v;
}
ll ans=-(u+v).best;
if(ans%2==1){
cout<<ans/2<<"."<<5<<" ";
}else{
cout<<ans/2<<" ";
}
}
return 6/22;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
104 ms |
1888 KB |
Output is correct |
10 |
Correct |
138 ms |
1876 KB |
Output is correct |
11 |
Correct |
38 ms |
1876 KB |
Output is correct |
12 |
Correct |
150 ms |
1880 KB |
Output is correct |
13 |
Correct |
40 ms |
2004 KB |
Output is correct |
14 |
Correct |
90 ms |
1876 KB |
Output is correct |
15 |
Correct |
87 ms |
1876 KB |
Output is correct |
16 |
Correct |
43 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
26424 KB |
Output is correct |
2 |
Correct |
154 ms |
28308 KB |
Output is correct |
3 |
Correct |
154 ms |
28248 KB |
Output is correct |
4 |
Correct |
141 ms |
26060 KB |
Output is correct |
5 |
Correct |
149 ms |
27412 KB |
Output is correct |
6 |
Correct |
145 ms |
26428 KB |
Output is correct |
7 |
Correct |
154 ms |
27464 KB |
Output is correct |
8 |
Correct |
147 ms |
26236 KB |
Output is correct |
9 |
Correct |
150 ms |
26096 KB |
Output is correct |
10 |
Correct |
170 ms |
28444 KB |
Output is correct |
11 |
Correct |
162 ms |
26872 KB |
Output is correct |
12 |
Correct |
157 ms |
27848 KB |
Output is correct |
13 |
Correct |
152 ms |
26048 KB |
Output is correct |
14 |
Correct |
153 ms |
28096 KB |
Output is correct |
15 |
Correct |
168 ms |
27984 KB |
Output is correct |
16 |
Correct |
150 ms |
26100 KB |
Output is correct |
17 |
Correct |
147 ms |
27448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
26424 KB |
Output is correct |
2 |
Correct |
154 ms |
28308 KB |
Output is correct |
3 |
Correct |
154 ms |
28248 KB |
Output is correct |
4 |
Correct |
141 ms |
26060 KB |
Output is correct |
5 |
Correct |
149 ms |
27412 KB |
Output is correct |
6 |
Correct |
145 ms |
26428 KB |
Output is correct |
7 |
Correct |
154 ms |
27464 KB |
Output is correct |
8 |
Correct |
147 ms |
26236 KB |
Output is correct |
9 |
Correct |
150 ms |
26096 KB |
Output is correct |
10 |
Correct |
170 ms |
28444 KB |
Output is correct |
11 |
Correct |
162 ms |
26872 KB |
Output is correct |
12 |
Correct |
157 ms |
27848 KB |
Output is correct |
13 |
Correct |
152 ms |
26048 KB |
Output is correct |
14 |
Correct |
153 ms |
28096 KB |
Output is correct |
15 |
Correct |
168 ms |
27984 KB |
Output is correct |
16 |
Correct |
150 ms |
26100 KB |
Output is correct |
17 |
Correct |
147 ms |
27448 KB |
Output is correct |
18 |
Correct |
295 ms |
26556 KB |
Output is correct |
19 |
Correct |
269 ms |
28160 KB |
Output is correct |
20 |
Correct |
160 ms |
28212 KB |
Output is correct |
21 |
Correct |
202 ms |
26216 KB |
Output is correct |
22 |
Correct |
229 ms |
26600 KB |
Output is correct |
23 |
Correct |
198 ms |
26444 KB |
Output is correct |
24 |
Correct |
271 ms |
26992 KB |
Output is correct |
25 |
Correct |
144 ms |
26032 KB |
Output is correct |
26 |
Correct |
295 ms |
26036 KB |
Output is correct |
27 |
Correct |
280 ms |
28552 KB |
Output is correct |
28 |
Correct |
225 ms |
26544 KB |
Output is correct |
29 |
Correct |
261 ms |
27928 KB |
Output is correct |
30 |
Correct |
196 ms |
26016 KB |
Output is correct |
31 |
Correct |
231 ms |
28024 KB |
Output is correct |
32 |
Correct |
190 ms |
27968 KB |
Output is correct |
33 |
Correct |
278 ms |
26092 KB |
Output is correct |
34 |
Correct |
215 ms |
27384 KB |
Output is correct |