Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main( )
- {
- FILE *in = fopen("input.txt", "rt");
- FILE *out = fopen("output.txt", "wt");
- if (in && out)
- {
- int n, m;
- fscanf(in, "%d %d", &n, &m);
- int matrix[n][m];
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < m; ++j)
- {
- fscanf(in, "%d", &matrix[i][j]);
- }
- }
- for (int i = 0; i < n; ++i)
- {
- for (int j = 0; j < m; ++j)
- {
- if (i != 0 || j != 0)
- {
- if (j == 0)
- {
- matrix[i][j] += matrix[i - 1][j];
- }
- else if (i == 0)
- {
- matrix[i][j] += matrix[i][j - 1];
- }
- else
- {
- matrix[i][j] += (matrix[i - 1][j] < matrix[i][j - 1]) ? matrix[i - 1][j] : matrix[i][j - 1];
- }
- }
- }
- }
- fprintf(out, "%d", matrix[n - 1][m - 1]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment