#include #include #include int cell_value = 0; int count_max = 0; long long int matrix_size = 0; long long int submatrix_count = 0; long long int sum = 0; long long int sum_total = 0; long long int max = 0; long long int top = 0; long long int left = 0; long long int bottom = 0; long long int right = 0; std::map* submatrix_sum_count; int** matrix_table; int main(int argc, char *argv[]) { // fast std::cin, declare in main() std::ios::sync_with_stdio(false); submatrix_sum_count = new std::map(); std::cin >> matrix_size; std::cin >> submatrix_count; matrix_table = new int*[matrix_size+1]; for(int row = 0; row < matrix_size+1; row++) { matrix_table[row] = new int[matrix_size+1]; // reset table matrix_table[row][0] = 0; matrix_table[0][row] = 0; } for(int row = 1; row < matrix_size+1; row++) { for(int column = 1;column < matrix_size+1; column++) { std::cin >> cell_value; matrix_table[row][column] = cell_value + matrix_table[row][column-1] + matrix_table[row-1][column] - matrix_table[row-1][column-1]; } } for(int submatrix = 0; submatrix < submatrix_count; submatrix++) { std::cin >> top; std::cin >> left; std::cin >> bottom; std::cin >> right; sum = matrix_table[bottom+1][right+1] - matrix_table[top][right+1] - matrix_table[bottom+1][left] + matrix_table[top][left]; (*submatrix_sum_count)[sum] = (*submatrix_sum_count)[sum] + 1; sum_total = sum_total + sum; } for(std::map::iterator it = submatrix_sum_count->begin(); it != submatrix_sum_count->end(); it++) { if(it->second > max) { count_max = 1; max = it->second; } else if(it->second == max) { count_max = count_max + 1; } } std::cout << submatrix_sum_count->size(); std::cout << " "; std::cout << count_max; std::cout << " "; std::cout << sum_total / submatrix_count; }