#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n;
cin>>n;
set <int> st;
for(int i=0;i<n;i++){
int x;
cin>>x;
st.insert(x);
}
int q;
cin>>q;
while(q--){
int x;
cin>>x;
int ans=0;
int next=x;
while(!st.empty()){
auto it=st.lower_bound(next);
int mn=1e18;
int cur=*it;
if(it!=st.begin()){
it--;
mn=min(mn,abs(cur-*it));
next=*it;
it++;
}
it++;
if(it!=st.end()){
if(abs(cur-*it)<mn){
mn=abs(cur-*it);
next=*it;
}
}
it--;
if(mn!=1e18)ans+=mn;
st.erase(it);
}
cout<<ans<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |