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. C#中 父类与子类相互强制转换之实验

    MSDN是很好,不过,有时需要自己动手实践一下,才能更好的理解和记住一些东西. 我看过很多技术文章,结果到用时,仍然是下不了手.似是而非的. 像上次写的“四舍六入五成双/四舍六入五留双/四舍六入五单双 ...

  2. Quartz学习笔记

    :30发送email通知客户最新的业务情况. java.util.Timer和java.util.TimerTask    Timer和TimerTask是能够完毕job schedule的两个jdk ...

  3. js和jquery判断事件流

    $('body').on('click',function(e){ var $target = $(e.target); if($target.parents('.fixNav>div').le ...

  4. SQL Server快速部署作业到多台服务器

    问题: 需要在很多的SQL Server服务器上创建相同的作业.我们可以一台一台的运行相同的脚本创建作业,但是有没有什么简便的做法呢? 解决方法: 可能很多人都没有注意到可以用多服务器环境管理SQL ...

  5. C++ 之 基础回顾(一)

    1  exe 程序

  6. Simple TCP/IP Echo Server & Client Application in C#

    1. TCP Server The server’s job is to set up an endpoint for clients to connect to and passively wait ...

  7. java实现双向循环链表

    java实现循环链表:http://www.cnblogs.com/lixiaolun/p/4643911.html 在单链表中,查询下一个元素的时间是O(1).查询上一个元素的时间却是O(n). 为 ...

  8. QtGui.QGridLayout

    The most universal layout class is the grid layout. This layout divides the space into rows and colu ...

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

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

  10. Java之JVM调优案例分析与实战(1) - 高性能硬件上的程序部署策略

    本JVM系列均来源于<深入理解Java虚拟机>一书中,版权归该书作者所有. 环境:一个15万PV/天左右的在线文档类型网站最近更换了硬件系统,新系统硬件为4个CPU.16GB物理内存.OS ...