http://codeforces.com/problemset/problem/954/E

式子变成Σ xi*(ti-T)=0

sum0表示>=T的ai*ti之和

sum1表示<T的ai*ti之和

那么如果sum0<sum1,所有ti>=T的ai全加上

那么现在的Σ xi*(ti-T)>=0

考虑用ti<T的来使这个式子变成0,还要让Σ xi 最大

显然是选的ti与T的差距越小 ,xi可以用的越多

将ti从大到小排序后,以此选用,直到式子变成0

sum1<sum0 时 同理

#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 200001 struct node
{
int a,t;
}e[N],z[N],f[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool cmp1(node p,node q)
{
return p.t<q.t;
} bool cmp2(node p,node q)
{
return p.t>q.t;
} int main()
{
int n,T;
read(n); read(T);
for(int i=;i<=n;++i) read(e[i].a);
for(int i=;i<=n;++i) read(e[i].t);
int cntz=,cntf=;
double sum0=,sum1=;
int cnt0=,cnt1=;
long long tot0=,tot1=;;
for(int i=;i<=n;++i)
if(e[i].t>=T)
{
z[++cnt0]=e[i];
sum0+=1LL*e[i].a*(e[i].t-T);
tot0+=e[i].a;
}
else
{
f[++cnt1]=e[i];
sum1+=1LL*e[i].a*(T-e[i].t);
tot1+=e[i].a;
}
sort(z+,z+cnt0+,cmp1);
sort(f+,f+cnt1+,cmp2);
double ans=;
if(sum0>=sum1)
{
ans=tot1;
for(int i=;i<=cnt0;++i)
if(1.0*z[i].a*(z[i].t-T)<=sum1)
{
sum1-=1.0*z[i].a*(z[i].t-T);
ans+=z[i].a;
}
else
{
ans+=sum1/(z[i].t-T);
break;
}
}
else
{
ans=tot0;
for(int i=;i<=cnt1;++i)
if(1.0*f[i].a*(T-f[i].t)<=sum0)
{
sum0-=1.0*f[i].a*(T-f[i].t);
ans+=f[i].a;
}
else
{
ans+=sum0/(T-f[i].t);
break;
}
}
printf("%.8lf",ans);
}

Codeforces 954 E. Water Taps的更多相关文章

  1. Codeforces 954E Water Taps

    题目大意 有 $n$($1\le n\le 200000$)个变量 $x_1, x_2, \dots, x_n$,满足 \begin{equation} 0\le x_i \le a_i \label ...

  2. Codeforces 954 G. Castle Defense

    http://codeforces.com/problemset/problem/954/G 二分答案 检验的时候,从前往后枚举,如果发现某个位置的防御力<二分的值,那么新加的位置肯定是越靠后越 ...

  3. Codeforces 954 D Fight Against Traffic

    Discription Little town Nsk consists of n junctions connected by m bidirectional roads. Each road co ...

  4. Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check

    A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...

  5. Educational Codeforces Round 40 (Rated for Div. 2) Solution

    从这里开始 小结 题目列表 Problem A Diagonal Walking Problem B String Typing Problem C Matrix Walk Problem D Fig ...

  6. Educational Codeforces Round 40 A B C D E G

    A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...

  7. Educational Codeforces Round 37 (Rated for Div. 2)

    我的代码应该不会被hack,立个flag A. Water The Garden time limit per test 1 second memory limit per test 256 mega ...

  8. C - Water The Garden

    It is winter now, and Max decided it's about time he watered the garden. The garden can be represent ...

  9. 10月清北学堂培训 Day 6

    今天是黄致焕老师的讲授~ T1 自信 AC 莫名 80 pts???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...

随机推荐

  1. [转载]SpringMVC的Model参数绑定方式

    SpringMVC的各种参数绑定方式 http://www.cnblogs.com/HD/p/4107674.html springMVC中复杂嵌套对象.List等集合类型数据绑定 http://ww ...

  2. Ping命令的另一种使用方法

    今天实习结束休息的时候无聊,于是便想看看机房有多少机器,IP是什么,有没有什么小漏洞. 依次使用了netstat.ping.Telnet以后,不小心输入了这样一个东西 当时按下回车以后,心里想的是这样 ...

  3. const修饰符限定的常量

    类型前加const修饰符限定变量为只读,称为常量,定义时必须初始化,且初始化后编译器不允许再修改常量的值. 一.常量的定义 const在类型前面 const int value: //value是co ...

  4. jenkins--svn基本使用

    新建项目 源码管理  #选择svn配置 svn基本信息配置 其中包括: Repository URL:  svn://10.101.0.XXX:9507/XXXX Credentials:  配置你的 ...

  5. Nodejs+Express+Mysql实现简单用户管理增删改查

    源码地址 https://github.com/king-y/NodeJs/tree/master/user 目录结构 mysql.js var mysql = require('mysql'); v ...

  6. 【题解】 bzoj1076: [SCOI2008]奖励关 (装压+期望dp)

    题面戳我 Solution 并不会做,看了下题解大概了解了.期望这个东西好难搞啊qwq 我们定义\(dp[i][j]\)表示第\(i\)步,拿到宝物前的状态为\(j\). 正着来会有很多不合法的情况, ...

  7. Android ListView 列表视图

    列表显示的三个元素 ListView : 用来显示列表的View Adapter : 适配器 用来把数据映射到ListView 上的中介 Data: 数据 将被映射的字符串,图片或者基本组件等资源 根 ...

  8. [hdu3466]Proud Merchants

    题目描述 Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and po ...

  9. 添加AD RMS role时,提示密码不能被验证The password could not be validated

    "The password could not be validated" when attempting to provision an AD RMS server. Sympt ...

  10. 【转】STC51单片机下载程序的时候不要在VCC端接DHT11

    今天使用51单片机学习板调试DHT11湿度传感器,下载程序的时候把DHT11烧掉了. 一开始我使用杜邦线把DHT11的VCC引脚接到学习板上的VCC端,GND接GND,数据端口接51单片机的P0.0. ...