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. What is the difference between apache tomcat deployer and core version? - Stack Overflow

    java - What is the difference between apache tomcat deployer and core version? - Stack Overflowhttps ...

  2. Weblogic 9.2和10.3 改密码 一站完成

    Weblogic 9.2和10.3可通用,只需修改参照如下配置即可: SET BEA_HOME=F:\beaSET JRE_HOME=%BEA_HOME%\jdk150_04\binSET LIB_H ...

  3. OA实例

    let express = require('express'); let consolidate = require('consolidate'); let bodyParser = require ...

  4. [日常工作]Oracle新增数据文件的小知识点

    1. 表空间是small file tablespace的 然后数据文件长到了32g左右之后无法再次扩充, 应用报错了 为了性能和最快的处理 使用语句 alter tablespace user ad ...

  5. codeforces437C

    The Child and Toy CodeForces - 437C On Children's Day, the child got a toy from Delayyy as a present ...

  6. BZOJ4723[POI2017]Flappy Bird——模拟

    题目描述 <飞扬的小鸟>是一款风靡的小游戏.在游戏中,小鸟一开始位于(0,0)处,它的目标是飞到横坐标为X的某个位置 上.每一秒,你可以选择点击屏幕,那么小鸟会从(x,y)飞到(x+1,y ...

  7. POJ3252-RoundNumbers-排列组合

    当一个数的二进制表示中,0的个数大于或等于1的个数时,叫做RoundNumber.求从S到F两个数(包含)之间的RoundNumber个数. 这类题一般都是先求出0到N的个数,然后两个相减. 由于题目 ...

  8. IDEA常见设置

    对于eclipse实在忍无可忍,各种功能各种bug..换回IDEA IDEA常见问题(其实不是问题,代码规范而已) 1.解决无限 This file is indented with tabs ins ...

  9. 洛谷P2054 [AHOI2005]洗牌(扩展欧几里德)

    洛谷题目传送门 来个正常的有证明的题解 我们不好来表示某时刻某一个位置是哪一张牌,但我们可以表示某时刻某一张牌在哪个位置. 设数列\(\{a_{i_j}\}\)表示\(i\)号牌经过\(j\)次洗牌后 ...

  10. Leetcode 217.存在重复元素 By Python

    给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 示例 1: 输入: [1,2,3,1] 输出: true ...