UVA Problem 11057 (Exact Sum) Solution

Problem Solving, UVa

#include <bits/stdc++.h>

using namespace std;



int main()

{

    int v[10010];

    //vector<int>v;

    int i,j,n,k,max,price1,a,price2,m,diff,tmp;



    while(cin>>n)

    {

        for(i=0;i<n;i++)

            cin>>v[i];

            //v.push_back(i);

        cin>>m;



        max=1000000;

        for(i=0;i<n-1;i++)

            for(j=i+1;j<n;j++)

            {

                if((v[i]+v[j])== m)

                {

                    diff=abs(v[i]-v[j]);

                        if(diff<max)

                        {

                            max=diff;

                            price1=v[i];

                            price2=v[j];

                        }

                }

            }

        if(price1>price2)

        {

            tmp=price1;

            price1=price2;

            price2=tmp;

        }

        printf("Peter should buy books whose prices are %d and %d.\n\n",price1,price2);

    }

    return 0;

}

 

0 Comments

You may find interest following article

Complete Guide: Create Laravel Project in Docker Without Local Dependencies

Create Laravel Project Through Docker — No Need to Install PHP, MySQL, or Apache on Your Local Machine In this tutorial, I’ll show you how to create and run a full Laravel project using Docker containers. That means you won’t have to install PHP, MySQL, or Apache locally on your computer. By the end of this guide, you’ll have a fully functional Laravel development...