| 15195 | 2025-02-16 12:12:19 | balinttt | Zebra (75 pont) | cpp17 | Forditási hiba |
#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;
open /var/local/lib/isolate/406/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:41:40: error: expected '}' at end of input
41 | cout << total_waiting_time << endl;
| ^
main.cpp:7:12: note: to match this '{'
7 | int main() {
| ^