Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 1 coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (≤, the total number of coins) and M (≤, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the two face values V​1​​ and V​2​​ (separated by a space) such that V​1​​+V​2​​=M and V​1​​≤V​2​​. If such a solution is not unique, output the one with the smallest V​1​​. If there is no solution, output No Solution instead.

Sample Input 1:

8 15
1 2 8 7 2 4 11 15

Sample Output 1:

4 11

Sample Input 2:

7 14
1 8 7 2 4 11 15

Sample Output 2:

No Solution

题目分析:二分搜索
 #define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
vector<int> V;
int main()
{
int N, M;
cin >> N >> M;
V.resize(N);
for (int i = ; i < N; i++)
cin >> V[i];
sort(V.begin(), V.end());
int flag = ,i;
for (i = ; i < N; i++)
{
if (binary_search(V.begin(), V.begin() + i, M - V[i]) || binary_search(V.begin() + i + , V.end(), M-V[i]))
{
flag = ;
break;
}
}
if (flag)
cout << V[i] << " " << M - V[i];
else
cout << "No Solution";
}

最新文章

  1. MySQL数据库罕见的BUG——Can&#39;t get hostname for your address
  2. Java基础知识(壹)
  3. MFC注册窗口类以及FindWindow按窗口类名查询
  4. C# 文件及文件夹深度复制
  5. linux yum下载RPM包后再安装LAMP环境
  6. 【Hibernate】Hibernate系列4之配置文件详解
  7. 二分查找法 java
  8. linux笔记:linux系统安装-linux系统安装
  9. Redis - 密码配置和主从复制
  10. jquery 工作空间注册
  11. sql语句用&#39;in&#39;执行多条语句时候,执行错误的解决方法
  12. Word中的公式向上偏或向下偏的解决方法
  13. MNIST机器学习
  14. 我的第一个Java程序
  15. [HNOI 2016]最小公倍数
  16. Deepin 15.4 破解安装 SecureFX-7.3 失败
  17. Spring Batch 远程分区和远程分块的区别
  18. Ubuntu14.04 下软件安装和卸载命令备记
  19. 链表回文判断(基于链表反转)—Java实现
  20. HDU 4990 Reading comprehension 简单矩阵快速幂

热门文章

  1. php+apache 环境配置(window环境)
  2. 【GTS-Fail】GtsSecurityHostTestCases#testNoExemptionsForSocketsBetweenCoreAndVendorBan
  3. Java自学路线图之Java框架自学
  4. Linux 文件系统及 ext2 文件系统
  5. MongoDB TTL索引的使用
  6. Array.isArray() 判断是不是数组
  7. Spring MVC启动流程分析
  8. 深入理解Java内存模型(摘)
  9. 037.集群网络-Docker网络实现
  10. github的上面的安全工具