#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
int N, Q;
cin >> N;
vector<int> sightseeing_spots(N);
for (int i = 0; i < N; i++) {
cin >> sightseeing_spots[i];
}
cin >> Q;
vector<int> starting_coordinates(Q);
for (int i = 0; i < Q; i++) {
cin >> starting_coordinates[i];
}
// Sort the sightseeing spots in ascending order
sort(sightseeing_spots.begin(), sightseeing_spots.end());
// Calculate and store the total traveling distances
for (int start_coordinate : starting_coordinates) {
long long total_distance = 0;
int current_position = start_coordinate;
priority_queue<pair<int, int>> pq;
for (int spot : sightseeing_spots) {
int distance = abs(spot - current_position);
pq.push({-distance, -spot});
}
while (!pq.empty()) {
int distance = -pq.top().first;
int spot = -pq.top().second;
pq.pop();
total_distance += distance;
current_position = spot;
}
cout << total_distance << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |