Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
917 B
3
Indexable
Never
#include <iostream>
#include <vector>

int averageWaitingTime(std::vector<std::vector<int>>& patients) {
    int totalWaitingTime = 0;
    int currentTime = 0;

    for (const auto& patient : patients) {
        int arrivalTime = patient[0];
        int examinationTime = patient[1];

        int waitingTime = std::max(0, currentTime - arrivalTime);
        totalWaitingTime += waitingTime;

        currentTime = std::max(currentTime, arrivalTime) + examinationTime;
    }

    return totalWaitingTime / patients.size();
}

int main() {
    int N;
    std::cin >> N;

    std::vector<std::vector<int>> patients(N);
    for (int i = 0; i < N; ++i) {
        int arrivalTime, examinationTime;
        std::cin >> arrivalTime >> examinationTime;
        patients[i] = {arrivalTime, examinationTime};
    }

    int averageTime = averageWaitingTime(patients);
    std::cout << averageTime << std::endl;

    return 0;
}
Leave a Comment