Skip to content

Instantly share code, notes, and snippets.

@TPAKC
Created April 22, 2015 17:52
Show Gist options
  • Save TPAKC/af294158166e4c793e79 to your computer and use it in GitHub Desktop.
Save TPAKC/af294158166e4c793e79 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class noob {
static int max;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(),m = in.nextInt();
int[][] a = new int[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) a[i][j] = in.nextInt();
int i = n - 1;
int j = m - 1;
while (i > 0) a[i - 1][j] += a[i--][j];
while (j > 0) a[n - 1][j - 1] += a[n - 1][j--];
for (i = n - 2; i >= 0; i--)
for (j = m - 2; j >= 0; j--) a[i][j] += max(a[i][j + 1], a[i + 1][j + 1], a[i + 1][j]);
System.out.println((a[0][0] > 0 ? "winner" : "loser") + "\n" + a[0][0]);
}
static int max(int a, int b, int c) {
if (a > b) max = a;
else max = b;
if (c > max) max = c;
return max;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment