알고리즘/백준

15235>Olympiad Pizza

Diademata 2024. 2. 18. 19:24
반응형

https://www.acmicpc.net/problem/15235

During the Olympiad finals we usually serve pizza for the contestants. When the food arrives, the contestants to queue to get some pizza. Each student will be given a single slice of pizza when his/her turn arrives. The problem is that some people need more than one slice of pizza to be well fed so they need to queue again for more pizza after they get the first one.
Given a list of slices needed to fed each of the contestants, compute how long it will take to fed all of them. We can give a slice of pizza every second and when a contestant is well fed he does not return to the queue.

code >>

#include <iostream>
#include<queue>
#include<vector>
int main()
{
    std::ios::ios_base::sync_with_stdio(false);
    int N = 0;
    std::cin >> N;
    std::vector<int> count(N);
    std::queue<int> q;
    for (int i= 0; i < N; ++i)
    {
        std::cin >> count[i];
        q.push(i);
    }
    std::vector<int> answer(N, 0);
    int time = 0;
    while (!q.empty())
    {
        int value = q.front();
        q.pop();
        time++;
        answer[value] = time;
        count[value]--;
        if (count[value] > 0)
        {
            q.push(value);
        }
    }
    for (int i = 0; i < N; i++)
    {
        std::cout << answer[i] << " ";
    }
    std::cout << "\n";
}

반응형