[蓝桥杯 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;
}
相关推荐
2301_78901562几秒前
算法与数据结构——排序算法大全
c语言·开发语言·数据结构·c++·算法·排序算法·visual studio
东风西巷39 分钟前
MobiPDF安卓版(PDF阅读编辑工具) 修改版
学习·pdf·电脑·软件需求
光头闪亮亮43 分钟前
基于 wxWidgets 框架的桌面应用程序-WebView 浏览器控件与Go后端数据交互
c++
无限进步_43 分钟前
冒泡排序的多种实现方式详解
c语言·数据结构·c++·算法
CVer_1 小时前
Pytorch学习之Dataset类
学习
兮山与1 小时前
算法7.0
算法
老花眼猫1 小时前
可自动求解的魔法游戏程序(C语言)
c语言·经验分享·青少年编程·课程设计
ajassi20002 小时前
开源 C++ QT QML 开发(十六)进程--共享内存
c++·qt·开源
new coder2 小时前
[算法练习]Day 7: 变长滑动窗口
数据结构·算法·leetcode
光影少年2 小时前
rust生态及学习路线,应用领域
开发语言·学习·rust