fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. int mer=0; // most excited row
  7. int lec=0; // least excited column
  8. cin >> n;
  9. int **table=new int *[n];
  10. for (int i=0; i<n; i++)
  11. table[i]= new int [n];
  12. for (int i=0; i<n; i++)
  13. for (int j=0; j<n; j++)
  14. cin >> table[i][j];
  15. int *exc= new int [n]; // excitation of the rows / columns
  16. for (int l=0; l<n; l++){
  17. exc[l]=0;
  18. for (int i=0; i<n; i++)
  19. exc[l]+=table[l][i];
  20. }
  21. for (int i=0; i<n; i++){
  22. if (exc[mer] < exc[i]){
  23. exc[mer]=exc[i];
  24. mer=i;
  25. }
  26. }
  27. for (int k=0; k<n; k++){
  28. exc[k]=0;
  29. for (int j=0; j<n; j++)
  30. exc[k]+=table[j][k];
  31. }
  32. for (int i=0; i<n; i++){
  33. if (exc[lec] > exc[i]){
  34. exc[lec]=exc[i];
  35. lec=i;
  36. }
  37. }
  38. cout << table[mer][lec];
  39. for (int i = 0; i < n; i++)
  40. delete []table[i];
  41. delete []table;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 15232KB
stdin
3
3 9 2 
13 1 0
3 1 7
stdout
2