# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729491 | Baytoro | Measures (CEOI22_measures) | C++17 | 1561 ms | 5348 KiB |
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>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=2e5+5;
int d;
int calc(vector<int> vec){
sort(all(vec));
int n=vec.size();
int l=-1,r=2e9;
while(r-l>1){
int md=(l+r)/2;
vector<int> a=vec;
for(int i=0;i<n;i++){
if(!i){
a[i]-=md;
continue;
}
int x=abs((a[i-1]+d)-a[i]);
//cout<<x<<endl;
if(x>md){
if(a[i]-md<a[i-1]+d) a[i]+=md;
else a[i]-=md;
}
else{
if(a[i]-x<a[i-1]+d) a[i]+=x;
else a[i]-=x;
}
/*cout<<md<<endl;
for(auto it: a)
cout<<it<<' ';
cout<<endl;*/
}
bool check=1;
for(int i=1;i<n && check;i++)
check&=(a[i]-a[i-1]>=d);
if(check) r=md;
else l=md;
}
return r;
}
vector<int> vec;
void solve(){
int n,m;cin>>n>>m>>d;
vec.resize(n);
for(int i=0;i<n;i++){
cin>>vec[i];
}
sort(all(vec));
int ans=0;
for(int i=0;i<m;i++){
int x;cin>>x;
auto it=lower_bound(all(vec),x);
vec.insert(it,x);
int cur=0;
for(int i=(int)vec.size()-2;i>=0;i--){
int D=d-(vec[i+1]-vec[i]);
cur=max(cur+D,0ll);
ans=max(ans,cur);
}
cout<<ans/2;
if(ans%2) cout<<".5";
cout<<' ';
}
}
main(){
//fopn("friendcross");
ios;
int T=1;
//cin>>T;
for(int i=1;i<=T;i++){
//cout<<"Case #"<<i<<": ";
solve();
}
}
Compilation message (stderr)
# | 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... |