[蓝桥杯 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;
}
相关推荐
Lhan.zzZ6 小时前
Qt WebEngineView 在 Linux 上无法加载网页:从“看不见 HTML“到“禁用沙箱“
linux·c++·qt
鬼手点金6 小时前
Agent 的学习机制:后训练、上下文学习与外部化学习
java·人工智能·git·学习·自动化·nanogpt
几个几个n6 小时前
LaTeX 入门学习
学习
Data analyse4566 小时前
rnweb 回放数据量太大怎么办?分片存储与断点续传的实现思路
前端·网络·算法·数据分析
员工风险管理实务7 小时前
职务侵占有什么价值?岗位关联性与必要性判断
职场和发展
sysu_chenxy7 小时前
二重循环输出二维图形
c++
Navigator_Z7 小时前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
想七想八不如114088 小时前
元学习简单入门
人工智能·pytorch·python·深度学习·学习·机器学习
Nil2088 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
光影少年8 小时前
AI Agent、自动化与未来工作
人工智能·算法·架构