尺取法 — 详解 + 例题模板(全)

尺取法 — 详解 + 例题模板(全)_lxt_Lucia的博客-CSDN博客_尺取法

2020CCPC秦皇岛

Professor Alex is preparing an exam for his students now.

There will be nn students participating in this exam. If student ii has a good mindset, he/she will perform well and get a_iai​ points. Otherwise, he/she will get b_ibi​ points. So it is impossible to predict the exam results. Assume the highest score of these students is xx points. The students with a score of no less than x \cdot p\%x⋅p% will pass the exam.

Alex needs to know what is the maximum number of students who can pass the exam in all situations. Can you answer his question?

Input

The first line of the input gives the number of test cases, T (1≤T≤5×10^3). TT test cases follow.

For each test case, the first line contains two integers n (1≤n≤2×10^5) andp (1≤p≤100), where nn is the number of students and p% is the ratio.

Each of the following nn lines contains two integers ai​,bi​ (1≤bi​≤ai​≤10^9), representing the scores of student i.

The sum of n in all test cases doesn't exceed 5×10^5.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1), and y is the maximum number of students.

Input

2
2 50
2 1
5 1
5 60
8 5
9 3
14 2
10 8
7 6

Output

Case #1: 2
Case #2: 4

AC代码:2020CCPC秦皇岛 Exam Results(尺取)_林苏泽-CSDN博客

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ull;
const ull Max=1e6+5;
struct node{
	ull val,id;
};
bool cmp(node a,node b){
	return a.val<b.val;
}
node pos[Max];
ull vis[Max];
ull res,ant,num,now;
int main(){
	ull T;scanf("%lld",&T);ull u=1;
	while(T--){
		res=1;
		ull n,p;scanf("%lld%lld",&n,&p);
		for(int i=1;i<=n;i++){
			ull x,y;scanf("%lld%lld",&x,&y);
			pos[res].val=x;
			pos[res].id=i;res++;
			pos[res].val=y;
			pos[res].id=i;res++;
			vis[i]=0;
		}
		res--;
		sort(pos+1,pos+1+res,cmp);
		now=0;num=0;
		while(now!=n){
			num++;
			if(vis[pos[num].id]==0){
				now++;
			}
			vis[pos[num].id]++;
		}
		ant=1;ull ans=0;
		vis[pos[num].id]--;num--;now--;
		while(num<res){
			num++;
			if(vis[pos[num].id]==0) now++;
			vis[pos[num].id]++;
			while(pos[ant].val*100<pos[num].val*p){
				if(vis[pos[ant].id]==1){
					now--;
				}
				vis[pos[ant].id]--;
				ant++;
			}
			ans=max(ans,now);
		}
		printf("Case #%lld: %lld\n",u,ans);u++;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瘾ิۣۖิۣۖิۣۖิꦿ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值