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. scrapy 爬网站 显示 Filtered offsite request to 错误

    爬取zol 网站图片,无法抓取. 在 setting.py 文件中 设置 日志 记录等级 LOG_LEVEL= 'DEBUG' LOG_FILE ='log.txt' 查看日志 发现报 2015-11 ...

  2. 安插,复制,替换和删除ul中的li

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. iOS 网易彩票-4设置模块一

    概述 基本上,每一款APP都有相应的设置模块.怎么设置才能更灵活和通用呢,这也是大家一直思考的.下面说说在网易彩票中,设置模块的设置思想. 基本上有三种方案: static cell(呆板,完全没有动 ...

  4. liferay项目经验之BasePortlet

    package com.ebizwindow.crm.portlet.base; import java.io.IOException; import java.io.InputStream; imp ...

  5. js里实现给数字加三位一逗号间隔的两种方法

    方法一: <script  type= "text/javascript"> var   num_s = "1232134456.546 ";ale ...

  6. input hidden的作用

    网上辣么多blabla的,我就总结一下 1 什么是hidden hidden 是input type的一个值,叫隐藏域,官方解释:“Hidden 对象代表一个 HTML 表单中的某个隐藏输入域. 这种 ...

  7. yii2csrf攻击

    第一种解决办法是关闭Csrf public function init(){ $this->enableCsrfValidation = false; } 第二种解决办法是在form表单中加入隐 ...

  8. python webdriver api-读取、设置配置文件

    文件结构: db.ini放置db信息的配置文件 文件中[gloryroad]是section信息 下边的dbname等是option信息 UiObjectMap.ini放置访问web的配置信息 配置用 ...

  9. python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法

    python3.4学习笔记(十九) 同一台机器同时安装 python2.7 和 python3.4的解决方法 同一台机器同时安装 python2.7 和 python3.4不会冲突.安装在不同目录,然 ...

  10. Jmeter--正则表达式提取器

    正则提取器的一般使用场景是, 在我第二个请求参数中需要加入第一个请求的返回值, 此时通过正则提取器可以提取第一个请求返回值中指定的字段信息并赋值, 在第二个请求参数中直接引用该变量即可 jmeter的 ...