[蓝桥杯 2019 省 A] 外卖店优先级

模拟 双指针

cpp 复制代码
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
#define int long long
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int n,m,ts;

bool vis[N];
int a[N];
int last[N];
pair<int,int>query[N];

void solve()
{
	cin>>n>>m>>ts;
	
	for(int i=1;i<=m;i++){
		int a,b;cin>>a>>b;
		query[i] = {a,b};
	}
	
	sort(query+1,query+1+m);
	
	
	for(int i=1;i<=m;){
		
		int j = i;
		while(j+1<=m&&query[j+1].second==query[i].second)j++;
		int len = j-i+1;
		
		int t = query[i].first,id = query[i].second;
		
		//t-1  last[t]+1
		a[id] -= t-1-last[id];
		if(a[id]<0)a[id] = 0;
		if(a[id]<=3)vis[id] = 0;
		
		last[id] = t;
		
		
		a[id] += len*2;
		
		if(a[id]>5)vis[id] = 1;
		
		i = j+1;
	}
	
	
	for(int i=1;i<=n;i++){
		if(vis[i]&&a[i]-ts+last[i]<=3)vis[i] = 0;
	}
	
	int cnt = 0;
	for(int i=1;i<=n;i++)if(vis[i]){cnt++;}
	cout<<cnt;
	
	

}

signed main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;
	//cin>>_;
	_ = 1;
	while(_--)solve();
	return 0;
}
相关推荐
晓蛋4 天前
c语言指的是什么意思
c语言·编译器·编程开发·集成开发环境·程序实例
一隅论数智4 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
倒头就睡的小比特4 天前
算法竞赛C++常用的STL
c++·算法
weilx12344 天前
C++笔记-文件IO-<fcntl.h>
c++
小羊没烦恼!4 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
傲世仙尊4 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
XiHongShi20164 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本4 天前
离散数学第六课
学习·离散数学
牵猫散步的鱼儿4 天前
重载、重写(覆盖)、重定义区别
c语言