【Enumeration】【Division】【Derivation】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

The meaning of the question: There are two service requirements to be satisfied, service S1 requires x1 amount of resources, and S2 requires x2 amount of resources. There are n servers to provide resources, and the i-th server can provide resources of a[i]. When you select a certain number of servers to provide resources for a service, the resource requirements will be shared among them equally, and each server is required to undertake resource requirements that do not exceed the resource requirements it can provide. Given a legal scheme, each server is either not assigned to any of the services, or is assigned to one of the services.

Sort the servers in ascending order of the resources they can provide. Enumerate the number of servers i allocated to S1, and then divide them into two in the a array, you can get which i servers are provided to S1, and they occupy a continuous segment in the a array.

And what to give to S2? There are two cases: 1. If there are k stations in the a array that can satisfy S2, and this k station does not intersect with the one given to S1, then give it the last k station.

②If there is no suffix of a that can satisfy S2 after the i station, then preprocess a thing: pre[i] represents (n-i+1)-need[i] (if the i-th station is to be used, then at least The total number of units to be used), and then ask for a prefix max for this thing. If there is a certain position j in front of the i station of S1, it can make pre[j]>=i, that is, the number of vacant units corresponding to j is greater than It is equal to the number of units occupied by S1, then you might as well count the need[j] units backward from the nth unit (skip the i unit of S1) and assign them to S2.

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct data{
	int val,pos;
	data(){}
	data(const int &val,const int &pos){
		this->val=val;
		this->pos=pos;
	}
};
bool cmp(const data &a,const data &b){
	return a.val!=b.val ? a.val<b.val : a.pos<b.pos;
}
int n,m1,m2;
data a[300005];
int premax[300005],premaxpos[300005],need[300005];
int main(){
	//freopen("d.in","r",stdin);
	scanf("%d%d%d",&n,&m1,&m2);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i].val);
		a[i].pos=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i){
		int tmp;
		if(m2%a[i].val==0){
			tmp=m2/a[i].val;
		}
		else{
			tmp=m2/a[i].val+1;
		}
		if((n-i+1)-tmp>premax[i-1]){
			premax[i]=(n-i+1)-tmp;
			premaxpos[i]=i;
			need[i]=tmp;
		}
		else{
			premax[i]=premax[i-1];
			premaxpos[i]=premaxpos[i-1];
			need[i]=need[i-1];
		}
	}
	int hou=0;
	for(int i=n;i>=1;--i){
		if(m2<=(ll)a[i].val*(ll)(n-i+1)){
			hou=i;
			break;
		}
	}
	if(!hou){
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;++i){
		int tmp;
		if(m1%i==0){
			tmp=m1/i;
		}
		else{
			tmp=m1/i+1;
		}
		data *p=lower_bound(a+1,a+n+1,data(tmp,0),cmp);
		if(p-a+i-1>n){
			continue;
		}
		if(hou>=p-a+i){
			puts("Yes");
			printf("%d %d\n",i,n-hou+1);
			for(int j=p-a;j<p-a+i;++j){
				printf("%d%c",a[j].pos,j==p-a+i-1 ? '\n' : ' ');
			}
			for(int j=hou;j<=n;++j){
				printf("%d%c",a[j].pos,j==n ? '\n' : ' ');
			}
			return 0;
		}
		else if(premax[p-a-1]>=i){
			puts("Yes");
			printf("%d %d\n",i,need[p-a-1]);
			for(int j=p-a;j<p-a+i;++j){
				printf("%d%c",a[j].pos,j==p-a+i-1 ? '\n' : ' ');
			}
			int cnt=0;
			for(int j=n;j>=1;--j){
				if(j>=p-a && j<p-a+i){
					continue;
				}
				++cnt;
				printf("%d%c",a[j].pos,cnt==need[p-a-1] ? '\n' : ' ');
				if(cnt==need[p-a-1]){
					break;
				}
			}
			return 0;
		}
	}
	puts("No");
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325147834&siteId=291194637