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. vertx 从Tcp服务端和客户端开始翻译

    写TCP 服务器和客户端 vert.x能够使你很容易写出非阻塞的TCP客户端和服务器 创建一个TCP服务 最简单的创建TCP服务的方法是使用默认的配置:如下 NetServer server = ve ...

  2. 剑指offer4

    中序遍历(LDR)是二叉树遍历的一种,也叫做中根遍历.中序周游.在二叉树中,先左后根再右.巧记:左根右. 现在有一个问题,已知二叉树的前序遍历和中序遍历:PreOrder:         GDAFE ...

  3. EditPlus 中文版停止更新

    经过一段时间的考虑,我决定了终止 EditPlus 的中文版翻译工作. 感谢各位网友在这么长时间内对本汉化项目的关注.

  4. 关于在ASP.NET中使用JavaScript的建议

    一个很恼人的情况,就是当你使用JS在一个ASP,NET应用程序中引用一个在模板页初始化的服务器控件的时候: 比如,我们在模板页有一个TextBox的服务器控件,而且我们想要去获取他的Text:如果你使 ...

  5. Linux服务器---apache配置文件

    Apache配置文件 Apache的配置文件默认路径是“/etc/httpd/conf/httpd.conf”,编辑该文件就可以修改Apache的配置 1.设置网页主目录,参数DocumentRoot ...

  6. Q_DECLARE_PRIVATE与Q_DECLARE_PUBLIC

    Q_DECLARE_PRIVATE与Q_DECLARE_PUBLIC 这两个宏在Qt的源码中随处可见,重要性不言而喻.在 部落格的 Inside Qt Series 系列文章中,他用了3篇文章来讲这个 ...

  7. web前端----JavaScript(JS)函数

    函数 函数定义 JavaScript中的函数和Python中的非常类似,只是定义方式有点区别. // 普通函数定义 function f1() { console.log("Hello wo ...

  8. Jsoup简介

    Jsoup简介 一.概述 Jsoup 是一款Java 的HTML解析器,可直接解析某个URL地址.HTML文本内容.它提供了一套非常省力的API,可通过DOM,CSS以及类似于jQuery的操作方法来 ...

  9. git和github的简单配合使用

    1.安装git,TortoiseGit. 2.用帐号A登陆github,建立一个版本仓库test1.用默认值创建就可以了. 3.在本机用TortoiseGit克隆仓库test1.直接选https开头的 ...

  10. 20145220韩旭飞《网络对抗》Exp7 网络欺诈技术防范

    20145220韩旭飞<网络对抗>Exp7 网络欺诈技术防范 应用SET工具建立冒名网站 要让冒名网站在别的主机上也能看到,需要开启本机的Apache服务,并且要将Apache服务的默认端 ...