답안 #861019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861019 2023-10-15T06:49:54 Z rati Bitaro's travel (JOI23_travel) C++14
0 / 100
0 ms 348 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -