1048. Find Coins

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.