This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mod 998244353
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<pair<pair<int,int>,int>,null_type,less<pair<pair<int,int>,int>>,rb_tree_tag,tree_order_statistics_node_update>;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,d;
cin>>n>>m>>d;
if(n){
d*=2;
vector<int>v(n);
for(auto &i:v){cin>>i;i*=2;}
while(m--){
int x;
cin>>x;
x*=2;
v.push_back(x);
sort(v.begin(),v.end());
int l=0,r=1000000000,mid,f;
r*=r;
while(l<=r){
mid=(l+r)/2;
vector<int>vv=v;
vv[0]-=mid;
bool bl=1;
for(int i=1;i<vv.size();i++){
vv[i]=max(vv[i]-mid,vv[i-1]+d);
if(abs(vv[i]-v[i])>mid)bl=0;
}
if(bl){
r=mid-1;
f=mid;
}else l=mid+1;
}
cout<<f/2;
if(f&1)cout<<".5";
cout<<' ';
}
}else{
d*=2;
int ls=INT_MIN;
int ans=0;
while(m--){
int x;
cin>>x;
x*=2;
int ogx=x;
// cout<<max(ls+d,x-ans)<<' ';
x=max(ls+d,x-ans);
int g=abs(x-ogx)-ans;
g=max(g,0ll);
ls=x-g/2;
ans+=g/2;
cout<<ans/2;
if(ans&1)cout<<".5";
cout<<' ';
}
}
}
/*
1
13
7 10 13 |4 |5 10| 8| 3 6 5 |7 10| 2
*/
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:31:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=1;i<vv.size();i++){
| ~^~~~~~~~~~
Main.cpp:41:17: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | if(f&1)cout<<".5";
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |