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. 在上已个Java Spring MVC项目基础上加MyBatis

    代码目录: /Users/baidu/Documents/Data/Work/Code/Self/HelloSpringMVC 1. 首先在resource目录加上jdbc.properties: d ...

  2. python2 python3编码问题记录

    最近在服务器上跑脚本,linux自带的是python 2.x,中文显示经常有问题,通过下面两篇终于弄懂了. https://www.cnblogs.com/575dsj/p/7112767.html ...

  3. Android -- 消息处理机制源码分析(Looper,Handler,Message)

    android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个Message Queue(消息队列),但是MQ被封装到Looper里面了,我们不会直接与MQ打交道,因 ...

  4. Java经典23种设计模式之行为型模式(三)

    本文接着介绍11种行为型模式里的备忘录模式.观察者模式.状态模式. 一.备忘录模式 在不破坏封装性的前提下,捕获一个对象的内部状态.并在该对象之外保存这个状态.这样以后就能够将该对象恢复到原先保存的状 ...

  5. MySQL插值语句

    insert into Daywork( fdayworkId, fuserId, fdate, fhours, fclaimdate ) values ( 2709, '1@2.3', '2013- ...

  6. 踩坑记:mysql timeStamp默认值0000-00-00 00:00:00 报错

    报错现象: 从mysql5.5数据库导出的数据结构放到mysql5.7.10 报错create_time timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00 ...

  7. Discuz常见小问题-如何禁止用户发言,快速删除某个用户的所有帖子

    用户-用户组,勾选批量编辑,然后点击批量编辑的链接   点击论坛相关-帖子相关,然后把指定用户组的允许发新话题设置为否,拉到底部,点击提交   以一个普通用户重新登录,尝试发帖报错,说明已经设置成功 ...

  8. Box layout

    Layout management with layout classes is much more flexible and practical. It is the preferred way t ...

  9. DB中耗时的 存储过程 及执行详细情况

    SELECT a.object_id, a.database_id, OBJECT_NAME(object_id, database_id) 'proc name', a.cached_time, a ...

  10. 【五年】Java打怪升级之路

    之前写过一篇帖子.就是关于工作经验分享的,近期非常多人私信我.所以博客这边再分享一次 这几年来,我最大的感想就是一句话:多看.多写.多想.多问.多分享.多优化.多运动... 1.[多看] 读万卷书,行 ...