Luogu P2278 Code

P2278

#include <cstdio>
#include <queue>

struct task
{
    int number;
    int need;
    int get;
    int grade;
    inline bool operator < (const task &b) const
    {
        return this->grade<b.grade||(this->grade==b.grade&&this->get>b.get);
    }
};

std::priority_queue<task,std::vector<task>,std::less<task>> wait;

int main()
{
    int num,get,times,grade;
    int time=-1;
    while(scanf("%d%d%d%d",&num,&get,&times,&grade)!=EOF)
    {
        while((!wait.empty())&&time+wait.top().need<=get)
        {
            time+=wait.top().need;
            printf("%d %d\n",wait.top().number,time);
            wait.pop();
        }
        if(!wait.empty())
        {
            task cache=wait.top();
            wait.pop();
            cache.need-=get-time;
            wait.push(cache);
        }
        wait.push({num,times,get,grade});
        time=get;
    }
    while(!wait.empty())
    {
        time+=wait.top().need;
        printf("%d %d\n",wait.top().number,time);
        wait.pop();
    }
    return 0;
}


转载自本人Luogu Blog这篇文章

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容