Created
September 13, 2020 21:56
-
-
Save gonaumov/86aaf6d94aada840cde30f845c3db296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int externalSize = scanner.nextInt(); | |
int internalSize = scanner.nextInt(); | |
int[][] matrix = new int[externalSize][internalSize]; | |
for (int i = 0; i < matrix.length; i++) { | |
for (int j = 0; j < matrix[i].length; j++) { | |
matrix[i][j] = scanner.nextInt(); | |
} | |
} | |
int tickets = scanner.nextInt(); | |
int row = 0; | |
int maximum = 0; | |
for (int i = 0; i < matrix.length; i++) { | |
int rowMax = 0; | |
for (int j = 0; maximum == 0 && j < matrix[i].length; j++) { | |
if (matrix[i][j] == 0) { | |
rowMax++; | |
} else { | |
rowMax = 0; | |
} | |
if (rowMax >= tickets) { | |
row = i; | |
maximum = rowMax; | |
break; | |
} | |
} | |
} | |
int result = maximum == 0 ? 0 : ++row; | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment