ZOJ 3908 Number Game(乱搞)
来源:互联网 发布:如何关闭阿里云 编辑:程序博客网 时间:2024/05/18 19:38
The bored Bob is playing a number game. In the beginning, there are n numbers. For each turn, Bob will take out two numbers from the remaining numbers, and get the product of them. There is a condition that the sum of two numbers must be not larger than k.
Now, Bob is curious to know what the maximum sum of products he can get, if he plays at most m turns. Can you tell him?
Input
The first line of input contains a positive integer T, the number of test cases. For each test case, the first line is three integers n, m(0≤ n, m ≤100000) and k(0≤ k ≤20000). In the second line, there are n numbers ai(0≤ ai ≤10000, 1≤ i ≤n).
Output
For each test case, output the maximum sum of products Bob can get.
Sample Input
24 2 71 3 2 43 2 32 3 1
Sample Output
142
Author: XIAN, Weizh
要存下来sort一下选前m大的multiset乱搞
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int maxn=(1e5+100)*2;int ans[maxn];multiset<int>S;multiset<int>::iterator it;int t,n,m,k;int main(){ int x; scanf("%d",&t); while(t--) { S.clear(); scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++) { scanf("%d",&x); if(x>0&&x<k) S.insert(x); } int tot=0; while(1) { if(S.size()<2) break; it=S.end();it--; S.erase(it); int x=*it; it=S.upper_bound(k-x); if(it==S.begin()) continue; it--; ans[tot++]=1LL*(*it)*x; S.erase(it); } sort(ans,ans+tot); int pos=tot-1; LL sum=0; while(m>0&&pos>=0) { m--; sum+=ans[pos--]; } printf("%lld\n",sum); } return 0;}
- ZOJ 3908 Number Game(乱搞)
- ZOJ 3908 Number Game
- ZOJ-3908-Number Game
- ZOJ 3908Number Game
- 【贪心】 ZOJ 3908 Number Game
- zoj 3908 Number Game(STL)
- ZOJ 3180 Number Game(数学啊 )
- ZOJ 1039 Number Game
- ZOJ - 3180 Number Game
- zoj 1039 Number Game
- zoj 1039 Number Game
- zoj 3180 Number Game
- zoj - 1039 Number Game
- zoj 3908 Number Game(zoj 2015年10月月赛F题)
- 【瞎搞】 ZOJ 3180 Number Game
- ZOJ 3908 Number Game (贪心+二分+multiset)
- ZOJ 1039 Number Game (状态压缩,记忆化搜索)
- ZOJ-3447---Doraemon's Number Game (贪心+大数)
- C++学习笔记17——函数重载
- 第六周-建立链栈算法库
- MyBatis配置一对一
- java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10047 nor current process
- HDU4460(最短路)
- ZOJ 3908 Number Game(乱搞)
- Android Canvas的常用方法
- Java实现进度条
- leetcode word-pattern
- <学习笔记>关于Hash集合以及Java中的内存泄漏
- HadoopHDFS源码解析
- intellij idea 配置extjs4.2
- 经纬度搜索(1)-Geohash算法原理
- 黑马程序员——JavaSE之多线程中关于锁的理解 二