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. environmentmap in unity

    真崩溃之前明明找到这个api了 然后没存 然后我就找不到了... 刚刚遇到个特别邪门的问题 调着调着 vs的断点都显示无效 重启unity vs 电脑都不好使 之后我双击了breakpoint窗口.. ...

  2. 一次WEB前端优化尝试

    今天对自己做的项目中的一个设计器界面加载速度上进行了优化,因为页面在加载的时候,感觉有点慢.首先,我用firefox的yslow和chrome的pagespeed进行了测试,效果如下,分数有点不同,但 ...

  3. C#和Java交互相关研究

    之前总觉得C#和Java可以交互应用,但是由于时间以及其他方面的原因,一直没有调研.今天抽空搜了一下,终于折腾出来了. 以下是我自己就C#和Java整合的一些提问和分析,如果有不对的地方,请路过的各位 ...

  4. http://blog.csdn.net/steveguoshao/article/details/38414145

    http://blog.csdn.net/steveguoshao/article/details/38414145

  5. SSIS实践入门1:我的第一个SSIS程序开发

    深圳,和你见面已经有23天的时间了,第10天敲定了我人生中的第三份工作,虽说不是和想象中的工作那么好,但是我感觉我已经提前进入了备战状态,接下来我希望自己在你的领土可以有所发展,深圳,一个人多的城市, ...

  6. 友元程序集(C# 和 Visual Basic)

    友元程序集(C# 和 Visual Basic) Visual Studio 2013 “友元程序集”是一种能够访问其他程序集的 Friend (Visual Basic) 或 internal (C ...

  7. [Angular-Scaled web] 4. Using ui-router's named views

    In the previous post, we use $stateProvider deriect to root url and using MainCtrl, categories.tmpl. ...

  8. MongoDB 基础命令 (MongoDB Shell)

    1.我们 mongodb 安装成功后,用上一篇的方法启动 mongodb服务 然后使用 mongodb shell 来做数据库的增删改查 2.创建数据库 语法: use 数据库名称 案例: > ...

  9. FileItem 出现部分中文乱码解决办法

    首先要进行两处的修改: 第一:如果你使用了上传文件的包, 如:ServletFileUpload sfu = new ServletFileUpload(factory); sfu.setHeader ...

  10. tomcat服务器开启gzip功能的方法

    http://blog.csdn.net/wang_159369/article/details/8107163 tomcat5.0以后的版本是支持对输出内容进行gzip格式的压缩的.该功能默认是关闭 ...