题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源。有n个服务器来提供资源,第i台能提供a[i]的资源。当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担给它们,要求每台服务器承担的资源需求不超过其所能提供的资源需求。给定一种合法的方案,每台服务器要么没有被分配给任何一个服务,或者被分配给其中一个服务。

对服务器按能提供的资源从小到大排序。枚举给S1分配的服务器数量i,然后在a数组中二分,就可以得到给S1提供的是哪i台服务器,它们占据了a数组中连续的一段。

然后给S2哪些呢?分两种情况:①倘若a数组最后存在k台能满足S2,并且这k台不与给S1的相交,那么不妨就给它这最后的k台。

②倘若这i台之后,不存在a的某个后缀能够满足S2,那么预处理一个东西:pre[i]代表(n-i+1)-need[i](倘若要使用第i台那么至少要使用的总台数),然后对这个玩意求个前缀max,如果S1的i台前存在某个位置j,能使得pre[j]>=i,就是说j所对应的能空出来的台数大于等于S1占据掉的台数,那么不妨从第n台,倒着数need[j]台(跳过S1的i台),分配给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;
}

【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution的更多相关文章

  1. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造

    http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义: ...

  2. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心

    http://codeforces.com/contest/967/problem/E 题目大意: 给你一个数组a,a的长度为n 定义:b(i) = a(1)^a(2)^......^a(i), 问, ...

  3. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心

    http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...

  4. 【推导】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) B. Mystical Mosaic

    题意:给你一个棋盘的最终局面. 你的一次操作可以选择一些行和列,将它们的交叉点染黑,不能重复选择某行或者某列.问你是否能经过数次操作之后,达到目标局面. 就枚举所有黑点,如果该点行列都没被标记,就给它 ...

  5. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)

    A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep

    http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pastu ...

  7. Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings

    题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2  由变化规则可得: ...

  8. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  9. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

随机推荐

  1. 关于UNIX的exec函数

    在UNIX系统中,系统为进程相关提供了一系列的控制原语,包括:进程fork,进程exit,进程exec,进程wait等服务. 该篇文章主要与进程exec服务有关,并记录了几个需要注意留意的点. 照例给 ...

  2. 2016.6.26——Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree 本题收获 1.树时使用递归 2.注意边界条件时输出的值,仔细阅读题意,若是面试时,问清边界条件. 题目: Given a binary tre ...

  3. 查看oracle数据库日志存放位置

    1,默认情况下,oracle的日志文件记录在$ORACLE/rdbms/log目录下 [oracle@oracle log]$ pwd /home/oracle/oracle/product/11.2 ...

  4. aarch64_a2

    asterisk-sounds-core-en_GB-1.5.0-2.fc26.noarch.rpm 2017-02-14 08:24 26K fedora Mirroring Project ast ...

  5. rsync本地及远程复制备份【原创】

    1.安装rsyncyum instsall rsync 2.本地复制 rsync -auq --progress --delete /tongbu1/ /tongbu2/ rsync -auq --p ...

  6. 十、springcloud之Consul注销实例

    @Autowired //com.ecwid.consul.v1.ConsulClient private ConsulClient consulClient; @PostMapping(" ...

  7. C# listView subitem 问本值 text 改变 界面会闪烁

    解决方法 就是重写ListView,然后设置双缓冲即可,然后再使用DoubleBufferListView,就不会闪烁了.下面的代码是DoubleBufferListView,并使用FrmMain来测 ...

  8. java基础56 HTML5的标签知识(网页知识)

    本文知识点(目录): 1.html常用标签    2.html实体标签    3.html媒体标签    4.html超链接标签    5.html图片标签    6.html标个标签 7.html框 ...

  9. Python基础 - MySQLdb模块

    安装 pip install MySQLdb 使用 去除一个数据库中所有的表 import MySQLdb def db_test(): conn = MySQLdb.connect(user='&l ...

  10. 在VirtualBox虚拟机中安装Centos操作系统怎么与本地XShell远程连接

    问题: 在VirtualBox安装好了CentOS操作系统后,我们怎么才可以用XSell连接虚拟机中的CentOS呢? 答案: (1)在windows下用cmd--ipconfig查看VirtualB ...