Problem G: Array C

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

Giving two integers  and  and two arrays  and  both with length , you should construct an array  also with length  which satisfied:

1.0≤CiAi(1≤in)

2.

and make the value S be minimum. The value S is defined as:

Input

There are multiple test cases. In each test case, the first line contains two integers n(1≤n≤1000) andm(1≤m≤100000). Then two lines followed, each line contains n integers separated by spaces, indicating the array Aand B in order. You can assume that 1≤Ai≤100 and 1≤Bi≤10000 for each i from 1 to n, and there must be at least one solution for array C. The input will end by EOF.

Output

For each test case, output the minimum value S as the answer in one line.

Sample Input

3 4
2 3 4
1 1 1

Sample Output

6
思路:首先我们会想找到最小的一直下去,但是有个A数组为上界不好处理,所以先将C数组全部修改成A数组,一直向下减,当C相加等于M的时候得到答案;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
struct is
{
ll l,r;
ll maxx;
ll num;
ll sum;
}tree[];
ll a[];
ll b[];
void buildtree(ll l,ll r,ll pos)
{
tree[pos].l=l;
tree[pos].r=r;
if(l==r)
{
tree[pos].num=a[l];
tree[pos].maxx=(a[l]*a[l]-(a[l]-)*(a[l]-))*b[l];
tree[pos].sum=a[l];
return;
}
ll mid=(l+r)/;
buildtree(l,mid,pos*);
buildtree(mid+,r,pos*+);
tree[pos].maxx=max(tree[pos*].maxx,tree[pos*+].maxx);
tree[pos].sum=tree[pos*+].sum+tree[pos*].sum;
}
void update(ll l,ll r,ll pos,ll change)
{
if(tree[pos].r==change&&tree[pos].l==change)
{
ll kk=tree[pos].num-;
tree[pos].num=kk;
tree[pos].maxx=(kk*kk-(kk-)*(kk-))*b[change];
tree[pos].sum=kk;
return;
}
ll mid=(l+r)/;
if(change<=mid)
update(l,mid,pos*,change);
else
update(mid+,r,pos*+,change);
tree[pos].sum=tree[pos*].sum+tree[pos*+].sum;
tree[pos].maxx=max(tree[pos*].maxx,tree[pos*+].maxx);
}
ll findmax(ll l,ll r,ll pos,ll gg)
{
if(tree[pos].l==tree[pos].r)
return tree[pos].l;
ll mid=(l+r)/;
if(tree[pos*].maxx==gg)
return findmax(l,mid,pos*,gg);
else
return findmax(mid+,r,pos*+,gg);
}
ll getans(ll l,ll r,ll pos)
{
if(l==r)
return tree[pos].num*tree[pos].num*b[l];
ll mid=(l+r)/;
return getans(l,mid,pos*)+getans(mid+,r,pos*+);
}
int main()
{
ll x,y,z,i,t;
while(~scanf("%lld%lld",&x,&y))
{
for(i=;i<=x;i++)
scanf("%lld",&a[i]);
for(i=;i<=x;i++)
scanf("%lld",&b[i]);
buildtree(,x,);
while(tree[].sum!=y)
{
ll pos=findmax(,x,,tree[].maxx);
update(,x,,pos);
}
printf("%lld\n",getans(,x,));
}
return ;
}
 

华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列的更多相关文章

  1. (hzau)华中农业大学第四届程序设计大赛网络同步赛 G: Array C

    题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...

  2. [HZAU]华中农业大学第四届程序设计大赛网络同步赛

    听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...

  3. 华中农业大学第四届程序设计大赛网络同步赛 J

    Problem J: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1766  Solved: 299[Subm ...

  4. 华中农业大学第四届程序设计大赛网络同步赛 I

    Problem I: Catching Dogs Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1130  Solved: 292[Submit][St ...

  5. 华中农业大学第四届程序设计大赛网络同步赛-1020: Arithmetic Sequence,题挺好的,考思路;

    1020: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MB Submit:  ->打开链接<- Descriptio ...

  6. 华中农业大学第五届程序设计大赛网络同步赛-G

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  7. 华中农业大学第五届程序设计大赛网络同步赛-L

    L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...

  8. 华中农业大学第五届程序设计大赛网络同步赛-K

    K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...

  9. 华中农业大学第五届程序设计大赛网络同步赛-D

    Problem D: GCD Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 179  Solved: 25[Submit][Status][Web B ...

随机推荐

  1. uva10905

    /* 很好的字符串 比较方法 很多个字符串 组成的 数字 需要最大 然后 比较 a和b 是 比较a+b 和b+a 的大小 */ #include<cstdio> #include<s ...

  2. 数据仓库基础(十二)Informatica组件(2)

    本文转载自:http://www.cnblogs.com/evencao/p/3152708.html 1.Router Transformation:在filter 组件中只能写一个过滤条件.而在R ...

  3. JavaScript的 基本数据类型---对象

    第一:Javascript对象是 第二:Javascript中 第三:Javascript的对象是数据: 第四:JavaScript 中的对象可以简单理解成"名称:值"对(name ...

  4. Advapi32.dll--介绍

    https://blog.csdn.net/zhoujielun123456/article/details/50338147 使用方法详见:OpsTotalService

  5. eclipse启动失败Could not create the Java virtual machine

    一直使用idea,今天有研究一个新功能,因为公司项目在idea,不想动idea或是切换工作空间之类.于是把我的老eclipse启起来,可谁成想,直接报错: 点击确定之后: 最后找到解决办法: 删掉 C ...

  6. JAVA学习调查问卷——20145101

    1.你对自己的未来有什么规划?做了哪些准备? 我希望在未来不管自己是否从事机要工作,都要做一个有能力,对社会能有所贡献的人.所以在现阶段我应该努力学习基础知识,夯实基本功,具备成为合格机要人的素质. ...

  7. 20145334赵文豪《网络攻防》 MSF基础应用

    实践目标 掌握metasploit的基本应用方式 掌握常用的三种攻击方式的思路. 实验要求 一个主动攻击,如ms08_067 一个针对浏览器的攻击,如ms11_050 一个针对客户端的攻击,如Adob ...

  8. 20165310 Java实验五《网络编程与安全》

    20165310 Java实验五<网络编程与安全> 任务一 题目:①编写MyBC.java实现中缀表达式转后缀表达式的功能:②编写MyDC.java实现从上面功能中获取的表达式中实现后缀表 ...

  9. Android移植学习笔记

    1.一头雾水不知道用什么编译环境,不知道用什么下载软件 编译软件:Ubuntu12.04(编译主机系统),JDK(Java) 下载软件: 模拟器: qemu

  10. CMD运行后关闭CMD 的窗口命令

    在命令前加上Start 例(打开服务管理):start services.msc