Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test cases, can you help him by solving it?

Given an array of N non-negative integers and an integer K, your task is to find two integers X and Y from the given array such that X × Y = K.

The chosen numbers must have different indices in the   array.

Input

The first line of input contains T (1 ≤ T ≤ 128), the number of test   cases.

The first line of each test case contains two integers: N (2 ≤ N ≤ 100,000) and K (1 ≤ K ≤ 100,000). The next line contains N space-separated integers, each between 0 and   100,000.

Output

For each test case, if there is no solution, print -1 on a single line. Otherwise print a single line with two space-separated integers X Y (X ≤   Y), where X and Y are two numbers from the given array and X × Y = K.

If there is more than one possible solution, print the one with the minimum   X.

Sample Input

Sample Output

4

2 6

6 12

-1

3 6 2

4 2

9

3 12

2 1

1 12

1 2

4 36

12 18

3 36

4 12

1 2 6

12

 

这道题说多了都是泪,在WA了几道题的情况下跑到这道题来写,还写得很快,导致区间分错,哎,以后要多注意开闭区间啊,天呐!!!!

#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
using namespace std; const int MX = 111111;
int num[MX];
int n, k; bool judge(int i, int mid)
{
if (num[i] * num[mid] >= k) return true;
else return false;
} int main()
{
//freopen("input.txt", "r", stdin);
int cas;
while (scanf("%d", &cas) != EOF)
{
while(cas--)
{
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
{
scanf("%d", &num[i]);
}
sort(num, num + n);
bool j = true;
for (int i = 0; i < n; i++)
{
int lower = i + 1;//就是它= =
int higher = n - 1;//它以后也要多留心!!!
while (lower <= higher)
{
int mid = (lower + higher) / 2;
if (judge(i, mid)) higher = mid - 1;
else lower = mid + 1;
}
if (num[lower] * num[i] == k)
{
j = false;
printf("%d %d\n", num[i], num[lower]);
break;
}
}
if (j) printf("-1\n");
}
}
return 0;
}

Codeforce - Runtime Error的更多相关文章

  1. com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind

    在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...

  2. Arcmap 安装完后使用出现visual fortran run-time error的解决方法

    今天将ArcGIS安装到自己的XP笔记本上,安装过程一帆风顺,但打开Arcmap使用的时候,出现了visual fortran run-time error. 下面是解决方法: 下载个Dforrt.d ...

  3. Qt Sqlite qwt 发布过程中碰到的问题runtime error

    qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...

  4. IE Unknown runtime error

    1. 在函数中使用原生的js的时候,有时在IE下会出现Unknown runtime error 火狐下正常 2. 解决办法, 将原生js改成jquery处理兼容问题 document.getElem ...

  5. Microsoft Visual C++ Runtime error解决方法

    1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...

  6. Microsoft Visual C++ Runtime Library Runtime Error的解决的方法

    打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...

  7. UVa 1402 Runtime Error 伸展树

    Runtime Error 到现在连样例也跑不出来!!! 调试了一晚上快要死了…… 知道错在哪里但是不会改,代码先扔在这里吧.看来不能太依赖模板啊orz…… #include <cstdio&g ...

  8. Mindjet MindManager 2012 从模板创建出现“Runtime Error pure virtual function call” 解决方法

    我的Mindjet MindManager 2012 Pro也就是MindManager10 在应用模板之后总会显示 Microsoft Visual C++ Runtime Library Runt ...

  9. mindmanager2012打开文件出现runtime error r6025 解决方式

    关于mindmanager 2012启动无法执行,提示c++错误 ---------------------------Microsoft Visual C++ Runtime Library---- ...

随机推荐

  1. HDU5115 Dire Wolf(区间DP)

    渐渐认识到区域赛更侧重的是思维及基本算法的灵活运用,而不是算法的量(仅个人见解),接下来要更多侧重思维训练了. 区间DP,dp[i][j]表示从i到j最终剩余第i 与第j只的最小伤害值,设置0与n+1 ...

  2. js 随机星星 document.createElement(); setAttribute()

    js 随机星星 document.createElement(); setAttribute() <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  3. iphone手机不同版本兼容、横竖屏

    /* 兼容问题*/ @media screen and (device-width: 320px) and (device-height: 480px) and (-webkit-device-pix ...

  4. UE对一个很长的字符按16位自动换行

    ① ②设定16个位 ③ ④结果

  5. Sypder上手

    准备用python来做数据分析,选择了Sypder 刚打开时有点蒙逼,工作目录直接就在C盘了,想切换一下,发现右边工具栏里有工程路径,发现原来默认是在c盘用户路径下创建了一个临时工程 于是直接菜单栏/ ...

  6. document.body / document.ducumentElement /等获取高度和宽度的区别 ----转载

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. Arduino101学习笔记(三)—— 101简介

    一.板子图示--摘自中文社区 二.技术规格 主控器 Intel Curie 工作电压 3.3V (I/O兼容5V) 输入电压 (推荐) 7-12V 输入电压 (极限) 6-20V 数字 I/O 14 ...

  8. 【工具】Git

    1.安装好Git以后,在开始菜单里找到Git->Git Bash,弹出一个命令窗口 2.设置邮箱 . 3.创建文件夹 4.创建版本库 5.将文件添加到缓存区中去 6.提交文件 7.检查是否还有文 ...

  9. 【转】【技术博客】Spark性能优化指南——高级篇

    http://mp.weixin.qq.com/s?__biz=MjM5NjQ5MTI5OA==&mid=2651745207&idx=1&sn=3d70d59cede236e ...

  10. [转载]const_cast

     1. 一个经典实例 /* 用法:const_cast<type_id> (expression) 该运算符用来修改类型的const或volatile属性.除了const 或volatil ...