#include <iostream>
#include <algorithm>
using namespace std;
int store[123456], st[123456], youxian[123456];
/*store[123456],这个数组存储第id号店的上一次有订单的时间
,st[123456],这个数组存储第id号店是不是在优先缓存中
youxian[123456]这个数组存储第id号店的得分*/
struct node {
/*存储每一个订单的时间和几号店*/
int ts, i;
} shuzu[123456];
bool cmp(node a, node b) {
/*然后先按照店的编号从小到大排序,然后再按照时间先后排序*/
if (a.i == b.i) return a.ts < b.ts;
return a.i < b.i;
}
int main() {
int n, m, t, ans = 0;
cin >> n >> m >> t;
//输入店的个数 输入数组的个数 和时间
for (int i = 0; i < m; i++) cin >> shuzu[i].ts >> shuzu[i].i;
sort(shuzu, shuzu + m, cmp);
//排序
//遍历
for (int i = 0; i < m; i++) {
//tt是时间 id是点好
int tt = shuzu[i].ts, id = shuzu[i].i;
//如果和上一次不相同就进行更新数组
if (tt != store[id]) youxian[id] = youxian[id] - store[id] - 1;
//如果小于0那就是0
youxian[id] = max(0, youxian[id]);
//如果小于3退出就绪
if (youxian[id] <= 3) st[id] = 0;
//没有意外就+2
youxian[id] += 2;
//如果大于 5置位 1
if (youxian[id] > 5) st[id] = 1;
//store 记录上一个订单时间
store[id] = tt;
}
//收尾工作
for (int i = 1; i <= n; i++) {
if (store[i] < t) {
youxian[i] -= t - store[i];
if (youxian[i] <= 3) st[i] = 0;
}
}
/*最后在遍历一下每个店求一共有多少个店在优先缓存中
*/
for (int i = 1; i <= n; i++)
if (st[i]) ans++;
cout << ans << endl;
return 0;
}
蓝桥杯外卖优先级
最新推荐文章于 2024-05-19 19:33:09 发布