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. 使用gradle构建多模块springboot项目,打jar包

    官方文档: https://spring.io/guides/gs/rest-service/  参考:http://blog.csdn.net/u013360850/article/details/ ...

  2. Spark Shuffle Write阶段磁盘文件分析

    这篇文章会详细介绍,Sort Based Shuffle Write 阶段是如何进行落磁盘的 流程分析 入口处: org.apache.spark.scheduler.ShuffleMapTask.r ...

  3. [py]类和实例方法/内建方法

    内建方法 dir(__builtins__) 类和实例方法对比 class person: def __init__(self, job): self.job = job name = "m ...

  4. mac shell终端编辑命令行快捷键

    Ctrl + d        删除一个字符,相当于通常的Delete键(命令行若无所有字符,则相当于exit:处理多行标准输入时也表示eof) Ctrl + h        退格删除一个字符,相当 ...

  5. tfs项目解绑及svn上传

    1.tfs解绑 file--源代码管理——tfs解绑 2.svn将本地的文件夹上传到server 右击--import--url--新建文件夹

  6. codeforces 461C

    这题说的是 给了一张长方形的纸 1*n 然后可以按照不同的做法去折这个纸张 他有两种操作,操作1 给了一个pi 点 然后将左边的纸往右边折,第2种操作是给了一个L 和 R 然后计算出 L和R 之间的纸 ...

  7. 文件和打印机共享 win7 and xp

    Win7 摘自:https://www.xp510.com/article/4249.html 首先开启服务 方法:开始---所有程序---附件---运行---输入services.msc----确定 ...

  8. Struts2 Spring Hibernate 框架整合 Annotation MavenProject

    项目结构目录 pom.xml       添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  9. Java HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述

    Java HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述 一.HSSFworkbook,XSSFworkbook,SXSSFworkbook区别简述 用Java ...

  10. WebService(JAX-WS、XFire、Axis三种)获取客户端ip

    WebService(JAX-WS.XFire.Axis三种)获取客户端ip JAX-WS.XFire.Axis三种webservice的获取客户端IP的简单实现过程: 1,基于JDK6 jax-ws ...