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

24 篇文章 0 订阅
5 篇文章 0 订阅

模拟 双指针

#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;
}

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值