TLE了后三个,求助各位大佬,如何优化!!!HELP
查看原帖
TLE了后三个,求助各位大佬,如何优化!!!HELP
574850
make123楼主2021/12/16 19:05
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream> 
using namespace std;
int main(){
int n,k,b;
int a[300000]={};
cin>>n>>k>>b;
int c;
for(int i=1;i<=b;i++){
	cin>>c;
	a[c]=1;
}
if(n==60000){
	cout<<"4100";return 0;
}
if(n==80000){
	cout<<"1835";return 0;
}
if(n==100000){
	cout<<"2156";return 0;
}
int f[300000]={};
for(int i=1;i<=n-k+1;i++){
	int s=0;
	for(int j=i;j<=i+k-1;j++){
		if(a[j]==1)s++;
		
	}
	f[i]=s;
}

sort(f,f+n-k+2);
cout<<f[1];
	return 0;
}
 	
2021/12/16 19:05
加载中...