# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968540 | gry3125 | Bitaro's travel (JOI23_travel) | C++14 | 3089 ms | 3896 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 <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> x(N);
for(int i=0;i<N;i++){
cin >> x[i];
}
int Q;
cin >> Q;
int s;
int dist;
vector<int> v(N);
int a, count;
int best, min;
for(int i=0;i<Q;i++){
cin >> s;
dist=0;
count=0;
fill(v.begin(), v.end(), 0);
a=find(x.begin(), x.end(), s)-x.begin();
if(a!=N){
v[a]=1;
count++;
}
while(count<N){
min = 1000000000;
for (int o = 0; o < N; o++) {
if (v[o] == 0) {
if (abs(s - x[o]) < min) {
best = o;
min = abs(s - x[o]);
}
}
}
dist+=abs(s - x[best]);
v[best]=1;
s=x[best];
count++;
}
cout << dist << "\n";
}
return 0;
}
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... |