Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MaxNetVulnerability {
- static int getMaxNetVulnerability(int[][] vulnerability) {
- int n = vulnerability.length;
- int m = vulnerability[0].length;
- int maxNetVulnerability = Integer.MIN_VALUE;
- for (int row1 = 0; row1 < n; row1++) {
- for (int row2 = row1 + 1; row2 < n; row2++) {
- int[][] subsetGrid = new int[2][m];
- subsetGrid[0] = vulnerability[row1];
- subsetGrid[1] = vulnerability[row2];
- int[] maxInColumns = new int[m];
- for (int col = 0; col < m; col++) {
- int max = Integer.MIN_VALUE;
- for (int row = 0; row < 2; row++) {
- max = Math.max(max, subsetGrid[row][col]);
- }
- maxInColumns[col] = max;
- }
- int minMaxInColumns = Integer.MAX_VALUE;
- for (int max : maxInColumns) {
- minMaxInColumns = Math.min(minMaxInColumns, max);
- }
- maxNetVulnerability = Math.max(maxNetVulnerability, minMaxInColumns);
- }
- }
- return maxNetVulnerability;
- }
- public static void main(String[] args) {
- int[][] vulnerability = {
- {1, 3, 1},
- {3, 1, 1},
- {1, 2, 2},
- {1, 1, 3}
- };
- int maxVulnerability = getMaxNetVulnerability(vulnerability);
- System.out.println("Maximum possible net vulnerability: " + maxVulnerability);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement