1048. Find Coins (25) time limit MS Memory limit 65536 KB code length limit 16000 B award Program StandardAuthor Chen, Yue
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 is a special requirement of the Payment:for each bill, she could only use exactly and coins to pay the ex Act amount. Since she has as many as coins and she, she definitely needs your help. You is supposed to tell hers, for any given amount of money, whether or not she can find the coins to pay for it.
Input Specification:
Each input file contains the one test case. For each case, the first line contains 2 positive numbers:n (<=105, the total number of coins) and M (<=103, the AMO Unt of money Eva have to pay). The second line contains N face values of the coins, which is all positive numbers no more than 500. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print in one line the both face values V1 and V2 (separated by a space) such that V1 + V2 = M and V1 &l T;= V2. If Such a solution is not unique, the output of 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
Submit Code
1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cstring>5#include <queue>6#include <vector>7#include <cmath>8#include <string>9#include <map>Ten#include <Set> One using namespacestd; A intline[100005]; - intMain () { - //freopen ("D:\\input.txt", "R", stdin); the intn,m; -scanf"%d%d",&n,&m); - inti,j; - for(i=0; i<n;i++){ +scanf"%d",&line[i]); - } +Sort (line,line+n); A at /*For (i=0;i<n;i++) { - cout<<i<< "" <<line[i]<<endl; - }*/ - -I=0; -j=n-1; in while(i<j) { - if(line[i]+line[j]>m) { toj--; + Continue; - } the if(line[i]+line[j]<m) { *i++; $ Continue;Panax Notoginseng } - Break; the } + if(i<j) { Aprintf"%d%d\n", Line[i],line[j]); the } + Else{ -printf"No solution\n"); $ } $ return 0; -}
pat1048. Find Coins (25)