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. Activiti Rest API tutorial

    http://192.168.66.182:8080/activiti-rest/service/repository/deployments/ {"data":[{"i ...

  2. jquery judge element exist

    http://learn.jquery.com/using-jquery-core/faq/how-do-i-test-whether-an-element-exists/ if ( $( " ...

  3. Wshshell 脚本简单学习

    WshShell 的简单语法 学习 同事给了一个脚本自动执行  部署命令 感觉挺好的 , 年前一直说要学习一下 但是一直没有学习(自己太懒了) 这次简单总结一下. 创建对象: Set WshShell ...

  4. 软件工程_6th weeks

    一.上次博客时说的UI,拖拉到现在才展示,完成了“登录,普通匹配,做题界面,做题结果”四项 功能: 二.单元测试工具 1.python单元测试工具   最近因为论文原因一直在用Python,Pytho ...

  5. python常用命令和基础运算符

    基础运算符 http://www.cnblogs.com/alex3714/articles/5465198.html 身份运算符:is is not成员运算符:in not in ##in 判断元素 ...

  6. awk、sed、grep三大shell文本处理工具之grep的应用

    1.基本格式grep pattern [file...](1)grep 搜索字符串 [filename](2)grep 正则表达式 [filename]在文件中搜索所有 pattern 出现的位置, ...

  7. YII2十三大特性2

    第十三 场景(scenario)的使用 例如:有三个场景,分别为创建,更新,确认回款 首先,定义所有的场景,及规则,如下所示: <?php namespace core\models; use ...

  8. FileStream文件流

    操作字节 文件流和文件的区别 文件不管大小,一次读写 文件流可以分块读写 //文件流的资源GC不会释放,所以需要使用using using (FileStream fsRead = new FileS ...

  9. nginx-日志统计

    #!/bin/bash fd=/tmp/log# pv 点击量echo "###################点击量 --$pv-- #########################&q ...

  10. Codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(dsu on tree)

    感觉dsu on tree一定程度上还是与点分类似的.考虑求出跨过每个点的最长满足要求的路径,再对子树内取max即可. 重排后可以变成回文串相当于出现奇数次的字母不超过1个.考虑dsu on tree ...