이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <time.h>
#include <cstdlib>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <map>
#include <set>
#include <iterator>
#include <deque>
#include <queue>
#include <sstream>
#include <array>
#include <string>
#include <tuple>
#include <chrono>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <list>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;
int tt = 1, n;
ll a[200005], dist, x[200005];
set<pair<ll, int>> st;
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
st.insert({a[i], i});
}
cin >> tt;
for(int i = 1; i <= tt; i++){
cin >> x[i];
ll sum = 0, pos = x[i];
while(!st.empty()){
ll x1 = 1e10, y1 = 1e10;
pair<ll, int> p1, p2;
if(st.begin()->first <= pos){
auto it = st.lower_bound({pos, 0});
it--;
x1 = pos - it->first;
p1 = *it;
}
if(st.rbegin()->first > pos){
auto it = st.upper_bound({pos, 0});
y1 = it->first - pos;
p2 = *it;
}
if(x1 <= y1){
sum += x1;
pos -= x1;
st.erase(p1);
}
else{
sum += y1;
pos += y1;
st.erase(p2);
}
}
cout << sum << "\n";
}
}
# | 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... |