PAT 甲级 1048. Find Coins (25)

来源:互联网 发布:apache bin httpd.exe 编辑:程序博客网 时间:2024/06/06 09:27

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 105coins 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 (<=105, the total number of coins) and M(<=103, 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 V1 and V2 (separated by a space) such that V1 + V2 = M and V1 <= V2. If such a solution is not unique, output the one with the smallest V1. If there is no solution, output "No Solution" instead.

Sample Input 1:
8 151 2 8 7 2 4 11 15
Sample Output 1:
4 11
Sample Input 2:
7 141 8 7 2 4 11 15
Sample Output 2:
No Solution
#include <iostream>#include <vector>#include <algorithm>#include <cstring>using namespace std;int a[1001];int main() {int n, m, temp;scanf("%d %d", &n, &m);for (int i = 0; i < n; i++) {scanf("%d", &temp);a[temp]++;}for (int i = 1; i < 1001; i++) {if (a[i]) {a[i]--;if (m > i&&a[m - i]) {printf("%d %d\n", i, m - i);return 0;}a[i]++;}}printf("No Solution");return 0;}

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 被担保公司骗了怎么办 大学考查课挂了怎么办 大订书机卡针了怎么办 做原创的衣服该怎么办 4s店强制上牌怎么办 小孩一读书就哭怎么办 小孩上中班还哭怎么办 14岁初中生厌学怎么办 加拿大签证拒签了怎么办 离婚后不给孩子抚养费怎么办 格力空调出现e1怎么办 联想一键恢复后怎么办 微盘密码忘记了怎么办 乐高零件丢了怎么办 tpu手机壳变黄怎么办 脚被铁钉扎了怎么办 孩子性格内向不善于交际怎么办 3岁宝宝胆小怕人怎么办 焦虑症又复发了怎么办 有强迫思维的人怎么办 微信图片是黑的怎么办 玩cf老是卡屏怎么办 玩cf电脑卡屏怎么办 u盘装系统蓝屏怎么办 三星a8无限重启怎么办 旋转轮胎车翻了怎么办 轮胎卸不下来了怎么办 饥荒生病的虫洞怎么办 不小心点了暗网怎么办 苹果手机id用不了怎么办 电脑病毒杀不掉怎么办 高考信息填错了怎么办 家长不给买手机怎么办 2个月宝宝吃奶少怎么办 铅笔断在肉里怎么办 文明6金币负了怎么办 存了理财急用钱怎么办 银行开户许可证丢了怎么办 hcg值低怎么办怎么补 定期存款纸丢了怎么办 我定期存折丢了怎么办