이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#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());
for (int start_coordinate : starting_coordinates) {
long long total_distance = 0;
int current_position = start_coordinate;
multiset<pair<int, int>> distances; // Multiset to handle spots with the same distance
for (int spot : sightseeing_spots) {
int distance = abs(spot - current_position);
distances.insert({distance, spot});
}
while (!distances.empty()) {
int distance = distances.begin()->first;
int spot = distances.begin()->second;
distances.erase(distances.begin());
total_distance += distance;
current_position = spot;
}
cout << total_distance << endl;
}
return 0;
}
# | 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... |