fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 20;
  5.  
  6. int main() {
  7. int n, m , x, y, mt[MAX_SIZE + 1][MAX_SIZE + 1];
  8. cin >> n >> m >> x >> y;
  9. for (int i = 1; i <= n; ++i) {
  10. for (int j = 1; j <= m; ++j) {
  11. cin >> mt[i][j];
  12. }
  13. }
  14.  
  15. int counterSteps = 0, ySteps = y, xSteps = x;
  16. int pointY = 0, pointX = 0;
  17. // 1 + 3 = 4.
  18. for (int i = 1; i <= n; ++i) {
  19. int a = 0, b = 0;
  20. for (int j = 1; j <= m; ++j) {// 1 , 2, 3, 4
  21. a = 1 + ySteps; // 4| 3 | 2
  22. b = 1 + xSteps; // 3| 2 | 1
  23.  
  24. if (pointY + a <= n && ySteps > -1) { // (0 + 4), (4 + 3NU), (4 + 2NU)
  25. pointY += a;// 4
  26.  
  27. ++counterSteps;// 1
  28. //cout << j <<" " << counterSteps <<" \n";
  29. }
  30. if (pointX + b <= n && xSteps > -1 ) { // (0 + 3), (3 + 2 ), (5 + 1NU),
  31. pointX += b; // 3, 5
  32.  
  33. ++counterSteps; // 2, 3
  34. }
  35. --ySteps;// 2
  36. --xSteps; // 1, 0
  37. }
  38.  
  39. }
  40. cout << counterSteps;
  41.  
  42. return 0;
  43. }
  44. //https://l...content-available-to-author-only...e.ro/page/2gluma-de-1-aprilie#319648
Success #stdin #stdout 0s 5320KB
stdin
4 4 
1 3 
1 2 3 4 
1 2 3 4 
1 2 3 4 
1 2 3 4 
stdout
3