Array C

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 581  Solved: 101
[Submit][Status][Web Board]

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

HINT

In the sample, you can construct an array [1,1,2](of course [1,2,1] and [2,1,1] are also correct), and  is 6.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
struct Node
{
long long a;
long long b;
long long c;
long long num;
int i;
bool operator < (const Node& t)const
{
return ((num>t.num)|| (num==t.num&&a<t.a)|| (num==t.num&&a==t.a&&b<t.b)||(num==t.num&&a==t.a&&b==t.b&&c<t.c)||(num==t.num&&a==t.a&&b==t.b&&c==t.c&&i<t.i));
} } node[];
set<Node>s; int main()
{
int n,m; while(scanf("%d%d",&n,&m)!=EOF)
{
long long res=;
long long sum=;
s.clear();
for(int i=; i<n; i++)
scanf("%I64d",&node[i].a);
for(int i=; i<n; i++)
scanf("%I64d",&node[i].b);
for(int i=; i<n; i++)
{
node[i].i=i;
node[i].c=node[i].a;
node[i].num=(*node[i].c-)*node[i].b;
res+=node[i].c*node[i].c*node[i].b;
sum+=node[i].a;
s.insert(node[i]);
}
// cout<<res<<endl;
Node tmp;
set<Node>::iterator iter;
for(int i=sum; i>m; i--)
{
// for(iter=s.begin(); iter!=s.end(); iter++)
// cout<<iter->num<<" ";
tmp=(*s.begin());
//cout<<tmp.num<<"***"<<res<<endl; s.erase(tmp);
res-=tmp.num;
tmp.c-=;
//out<<tmp.a<<endl;
tmp.num=(*tmp.c-)*tmp.b;
s.insert(tmp); //cout<<endl; }
printf("%lld\n",res); }
return ;
}

华农校赛--G,用set比较大小,缩短时间复杂度的更多相关文章

  1. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

  2. 2016年省赛 G Triple Nim

    2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...

  3. 2020安徽程序设计省赛 G序列游戏

    2020安徽程序设计省赛 G序列游戏 有一个序列w,初始为空.再给出一个长度为m 单调递增的序列a.你需要对序列w 作如下n 次操作: (1)操作0,在序列尾部添加数字0. (2)操作1,在序列尾部添 ...

  4. 第八届河南省赛G.Interference Signal(dp)

    G.Interference Signal Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 17 [Submit][Status ...

  5. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  6. HUT 排序训练赛 G - Clock

    Clock Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u [Submit]   [Go ...

  7. 华中校赛 14th

    https://www.nowcoder.com/acm/contest/106#question A 分类讨论 #include<bits/stdc++.h> using namespa ...

  8. 2015安徽省赛 G.你来擒孟获

    http://xcacm.hfut.edu.cn/problem.php?id=1211 SPFA模板题目 最短路变种,从起点终点各找一次最短路相加 #include<iostream> ...

  9. 2016年省赛G题, Parenthesis

    Problem G: Parenthesis Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 398  Solved: 75[Submit][Status ...

随机推荐

  1. SQL Server 2008新特性——策略管理

    策略管理是SQL Server 2008中的一个新特性,用于管理数据库实例.数据库以及数据库对象的各种属性.策略管理在SSMS的对象资源管理器数据库实例下的“管理”节点下,如图: 从图中可以看到,策略 ...

  2. Echarts的legend改变图例图标为自定义图片

    当折线图时,legend默认时rect形式,如果需要改图例形状,可以自己设置legend的icon属性 legend: { icon:'stack' }, 1.自定义每个图例样式:为data的每个对象 ...

  3. PHP判断{函数/类/方法/属性}是否存在

    1.php判断系统函数或自己写的函数是否存在 bool function_exists ( string $function_name ) 判断函数是否已经定义,例如: if(function_exi ...

  4. Hibernate之一对一关联映射

    Hibernate中一对一关联映射共分为两种,一种是一对一主键关联映射,另一种是一对一唯一外键关联映射.下面简单介绍一下这两种关联映射. 一对一主键关联映射 一对一主键关联映射的两个实体有相同的ID. ...

  5. (转) [Flash/Flex] 用柏林噪音和滤镜制作翻腾的火焰效果----Flash AS3效应

    下图展示的是通过柏林噪声和一些滤镜制作的火焰效果.这个效果是从舞台底部燃起的熊熊烈火.这个效果使用了BitmapData里的perlinNoise方法,以及ColorMatrixFilter和Disp ...

  6. 同步网络时间到linux服务器(先修改时区再进行同步网络时间)

    查看时区:date -R 修改整个系统时区: rm -f /etc/localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 网 ...

  7. Android DataBinding库(MVVM设计模式)

    什么是MVVM 说到DataBinding,就有必要先提起MVVM设计模式.Model–View–ViewModel(MVVM) 是一个软件架构设计模式,相比MVVM,大家对MVC或MVP可能会更加熟 ...

  8. 【转】IT新人如何快速成长

    主动积极 主动积极包括很多方面了,主动学习.主动思考.主动承担责任等等.我觉得主动性很重要,如果你能做到这一点,那么肯定会把工作做的很好的. 学会学习 公司不是学校,需要改变由老师灌输知识的学习方式. ...

  9. MySQL 清理slowlog方法

    MySQL 清理slowlog方法 SET GLOBAL slow_query_log = 'OFF'; ALTER TABLE mysql.slow_log RENAME mysql.slow_lo ...

  10. 公司测试服务器 vimrc 配置文件

    " /etc/vimrc (configuration file for vim only) " author: Klaus Franken <kfr@suse.de> ...