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 Shehas as many as 5 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. The first line contains 2 positive numbers:n (<=105, the total number of coins) and M (<=103, The amount 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 on one line the both face values V1 and v2 (separated by a space) such that V1 + v 2 = M and v 1 <= 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.
#include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm>using namespace std;vector<int> Coin;int Main () { int i,n,m,temp; scanf ("%d%d", &n,&m); for (i=0;i<n;i++) { scanf ("%d", &temp); Coin.push_back (temp); } Sort (Coin.begin (), Coin.end ()); int low=0,high=coin.size () -1,sum=0; if (Low==high) { printf ("No solution\n"); System ("pause"); return 0; } for (;low
1048. Find Coins