151962025-02-16 12:12:32balintttZebra (75 pont)cpp17Wrong answer 0/751ms508 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n; // number of pedestrians
    cin >> n;

    vector<int> directions(n); // direction of crossing for each pedestrian
    vector<int> arrival_times(n); // arrival time of each pedestrian
    vector<int> waiting_times(n); // minimum waiting time for each pedestrian

    // read input
    for (int i = 0; i < n; i++) {
        cin >> directions[i];
        cin >> arrival_times[i];
    }

    // sort pedestrians by arrival time
    sort(arrival_times.begin(), arrival_times.end());

    // calculate minimum waiting times
    for (int i = 0; i < n; i++) {
        int min_waiting_time = 0;
        for (int j = 0; j < n; j++) {
            if (j != i && arrival_times[j] < arrival_times[i]) {
                min_waiting_time = max(min_waiting_time, arrival_times[j] - arrival_times[i]);
            }
        }
        waiting_times[i] = min_waiting_time;
    }

    // calculate total waiting time
    int total_waiting_time = 0;
    for (int i = 0; i < n; i++) {
        total_waiting_time += waiting_times[i];
    }

    cout << total_waiting_time << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/75
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms500 KiB
3Wrong answer0/51ms316 KiB
4Wrong answer0/51ms316 KiB
5Wrong answer0/51ms316 KiB
6Wrong answer0/51ms316 KiB
7Wrong answer0/51ms316 KiB
8Wrong answer0/51ms508 KiB
9Wrong answer0/51ms316 KiB
10Wrong answer0/51ms316 KiB
11Wrong answer0/51ms500 KiB
12Wrong answer0/51ms316 KiB
13Wrong answer0/51ms316 KiB
14Wrong answer0/51ms508 KiB
15Wrong answer0/51ms316 KiB
16Wrong answer0/51ms316 KiB
17Wrong answer0/51ms316 KiB