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

  1. 3 4
  2. 2 3 4
  3. 1 1 1

Sample Output

  1. 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.

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<stdlib.h>
  5. #include<cmath>
  6. #include<algorithm>
  7. #include<set>
  8. using namespace std;
  9. struct Node
  10. {
  11. long long a;
  12. long long b;
  13. long long c;
  14. long long num;
  15. int i;
  16. bool operator < (const Node& t)const
  17. {
  18. 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));
  19. }
  20.  
  21. } node[];
  22. set<Node>s;
  23.  
  24. int main()
  25. {
  26. int n,m;
  27.  
  28. while(scanf("%d%d",&n,&m)!=EOF)
  29. {
  30. long long res=;
  31. long long sum=;
  32. s.clear();
  33. for(int i=; i<n; i++)
  34. scanf("%I64d",&node[i].a);
  35. for(int i=; i<n; i++)
  36. scanf("%I64d",&node[i].b);
  37. for(int i=; i<n; i++)
  38. {
  39. node[i].i=i;
  40. node[i].c=node[i].a;
  41. node[i].num=(*node[i].c-)*node[i].b;
  42. res+=node[i].c*node[i].c*node[i].b;
  43. sum+=node[i].a;
  44. s.insert(node[i]);
  45. }
  46. // cout<<res<<endl;
  47. Node tmp;
  48. set<Node>::iterator iter;
  49. for(int i=sum; i>m; i--)
  50. {
  51. // for(iter=s.begin(); iter!=s.end(); iter++)
  52. // cout<<iter->num<<" ";
  53. tmp=(*s.begin());
  54. //cout<<tmp.num<<"***"<<res<<endl;
  55.  
  56. s.erase(tmp);
  57. res-=tmp.num;
  58. tmp.c-=;
  59. //out<<tmp.a<<endl;
  60. tmp.num=(*tmp.c-)*tmp.b;
  61. s.insert(tmp);
  62.  
  63. //cout<<endl;
  64.  
  65. }
  66. printf("%lld\n",res);
  67.  
  68. }
  69. return ;
  70. }

华农校赛--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. Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax

    So you want to spit out some XML from SQL Server into a file, how can you do that? There are a coupl ...

  2. C++如何禁止掉对象的复制操作

    最容易想到的是将拷贝构造函数与赋值函数声明为private.但是,private只是说外部不能直接调用,但是可以间接通过类的成员函数与友元函数对其访问.那么怎么办呢? ---->在类中,允许声明 ...

  3. hadoop常见问题总结1

    本文地址:http://www.cnblogs.com/archimedes/p/hadoop-problem1.html,转载请注明源地址. 问题1:http://localhost:50030 H ...

  4. Vue.js前后端同构方案之准备篇——代码优化

    收录待用,修改转载已取得腾讯云授权 导语 目前Vue.js的火爆不亚于当初的React,本人对写代码有洁癖,代码也是艺术.此篇是准备篇,工欲善其事,必先利其器.我们先在代码层面进行优化,对我们完成整个 ...

  5. (C++)浅谈多态基类析构函数声明为虚函数

    主要内容: 1.C++类继承中的构造函数和析构函数 2.C++多态性中的静态绑定和动态绑定 3.C++多态性中析构函数声明为虚函数 1.C++类继承中的构造函数和析构函数 在C++的类继承中, 建立对 ...

  6. ASP.NET HTTP500错误怎么办

    如图所示,HTTP500错误. 第一步:"开始"->"设置"->"控制面板"->"管理工具"-> ...

  7. ASP.NET缺少程序集引用怎么办

    如下所示,提示缺少Windows的引用,在using System.Windows.Forms;有一个下划线 错误代码为: 错误    1    命名空间"System"中不存在类 ...

  8. ArcGIS Add-In调试无法重新生成

    在调试ArcGIS Add-In时,出现错误:无法注册程序集"……\Projects\ArcGISAddIn\ArcGISAddIn\bin\Debug\ArcGISAddIn.dll&qu ...

  9. 在linux下安装mysql

    1.下载mysql 下载地址: http://dev.mysql.com/downloads/mysql/5.5.html#downloads 2.进入系统后,检测是否安装mysql #rpm -qa ...

  10. Python中的作用域

    Python中的作用域 Python 中,一个变量的作用域总是由在代码中被赋值的地方所决定的. 当 Python 遇到一个变量的话他会按照这样的顺序进行搜索: 本地作用域(Local)→当前作用域被嵌 ...