AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
  • 吐槽
  • 登录/注册

AcWing 1241. 外卖店优先级

作者: 作者的头像   那必须得是我了 ,  2023-01-21 17:52:59 ,  所有人可见 ,  阅读 4


0


#include<iostream>
#include<algorithm>

#define x first
#define y second

using namespace std;

const int N = 1e5+10;

typedef pair<int, int> PII;

bool st[N];//是否在优先队列中
int last[N];//表示第i个店铺上一次有订单的时刻
int score[N];//表示第i个店铺当前的优先级
int n,m,T;

PII order[N];//时间-店名

int main()
{
    scanf("%d%d%d", &n,&m,&T);
    for(int i=0;i<m;i++)    scanf("%d%d", &order[i].x,&order[i].y);
    sort(order,order+m);

    for(int i=0;i<m;)
    {
        int j=i;
        while(j<m && order[j] == order[i])  j++;
        int t=order[i].x, id=order[i].y, cnt=j-i;
        i=j;
        score[id] -=t-last[id]-1;
        if(score[id] < 0)   score[id] = 0;
        if(score[id] <= 3)  st[id] = false;

        score[id] += cnt*2;
        if(score[id] > 5)   st[id] = true;
        last[id] = t;
    }

    for(int i=1;i<=n;i++)
    {
        if(last[i] < T)
        {
            score[i] -= T - last[i];
            if(score[i] <= 3)   st[i] = false;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)   ans+=st[i];
    cout<<ans<<endl;

    return 0;
}

0 评论

你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息