Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created September 13, 2020 21:56
Show Gist options
  • Save gonaumov/86aaf6d94aada840cde30f845c3db296 to your computer and use it in GitHub Desktop.
Save gonaumov/86aaf6d94aada840cde30f845c3db296 to your computer and use it in GitHub Desktop.
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