Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static String organizingContainers(int[][] container) {
- boolean res = false;
- int n = container.length;
- for (int i = 0; i < n; i++) {
- // number of balls of different colour than i
- for (int j = 0; j < n; j++) {
- int diffBalls = 0;
- for (int k = 0; k < n; k++) {
- if (k != i) {
- diffBalls += container[j][k];
- }
- }
- // number of balls of colour i in different containers
- int ballsOutside = 0;
- for (int k = 0; k < n; k++) {
- if (k != j) {
- ballsOutside += container[k][i];
- }
- }
- res |= ballsOutside == diffBalls;
- }
- System.out.println(res);
- }
- return res ? "Possible" : "Impossible";
- }
Advertisement
Add Comment
Please, Sign In to add comment