UVA11057:

Exact Sum

#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;

int main(){

	int n, ni, m;
	
	while(cin >> n){
		
		int array[n];
		for(int i = 0; i < n; i++){
			cin >> ni;
			array[i] = ni;
		}
		cin >> m;

		sort(array, array + n);

		int max = 0;
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				if(array[i] + array[j] == m){
					max = array[i];
				}
			}
		}

		cout << "Peter should buy books whose prices are " << max << " and " << m - max << "." << endl;
		cout << endl;


	}

	return 0;


}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel