#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> sightseeing_spots(N);
for (int i = 0; i < N; i++) {
cin >> sightseeing_spots[i];
}
int Q;
cin >> Q;
for (int q = 0; q < Q; q++) {
int start_coordinate;
cin >> start_coordinate;
vector<long long> distance(N, numeric_limits<long long>::max());
set<pair<long long, int>> pq;
for (int i = 0; i < N; i++) {
long long d = abs(start_coordinate - sightseeing_spots[i]);
pq.insert({d, i});
distance[i] = d;
}
long long total_distance = 0;
while (!pq.empty()) {
int i = pq.begin()->second;
long long d = pq.begin()->first;
pq.erase(pq.begin());
if (d > distance[i]) {
continue;
}
total_distance += d;
for (int j = 0; j < N; j++) {
if (i != j) {
long long new_distance = abs(sightseeing_spots[i] - sightseeing_spots[j]);
if (new_distance < distance[j]) {
pq.erase({distance[j], j});
distance[j] = new_distance;
pq.insert({distance[j], j});
}
}
}
}
cout << total_distance << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |