반응형

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";
}

반응형

'알고리즘 > 백준' 카테고리의 다른 글

1766>문제집  (0) 2019.03.12
1654>랜선 자르기  (0) 2019.02.18
1010>다리놓기  (0) 2018.12.17
11657>타임머신  (0) 2018.12.04
1786>찾기  (0) 2018.11.26

+ Recent posts