344B - Simple Molecules - CodeForces Solution


brute force graphs math *1200

Please click on ads to support us..

Python Code:

a, b, c = [int(x) for x in input().split()]

z = (int)(1/2 * (c+b-a))
y = (int)(b - z)
x = (int)(a - y)

imposible = False

if (c+b-a) % 2 != 0:
    imposible = True
elif (a+b+c) % 2 != 0:
    imposible = True
elif (x < 0 or y < 0 or z < 0):
    imposible = True

if (imposible):
    print("Impossible")
else:
    print(y, z, x)
					 	  		 	   		 			 		 				

C++ Code:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

void solve() {
  int a, b, c;

  cin >> a >> b >> c;

  int fx = -1, y, z;
  for (int x = 0; x <= a; ++x) {
    z = a - x;
    y =  b - x;
    if (z >= 0 && y >= 0 && c - z == y && z + y == c && x + y == b && z + x == a) {
      fx = x;
      break;
    }
  }

  if (fx == -1) {
    cout << "Impossible";
    return;
  }

  cout << fx << ' ' << y << ' ' << z;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t = 1;
  // cin >> t;
  while (t--) solve();

  return 0;
}
 			   		  		  	 				      	


Comments

Submit
0 Comments
More Questions

892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC