UVA10812:

Beat the Spread!

#include <iostream>
#include <cmath>

using namespace std;

int main(){
	long long s1, s2, n, a, b;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s1 >> s2;

		b = abs(s1 - s2)/2;

		a = s1 - b;

		if(a + b != s1 || abs(a - b) != s2){
			cout << "impossible" << endl;
		} else if (a > b) {
			cout << a << " " << b << endl;
		} else if (a <= b){
			cout << b << " "  << a << endl;
		}
	}
	return 0; 
}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel