fork(1) 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. --ySteps;// 2
  24. --xSteps; // 1, 0
  25. if (pointY + a <= n && ySteps > -1) { // (0 + 4), (4 + 3NU), (4 + 2NU)
  26. pointY += a;// 4
  27.  
  28. ++counterSteps;// 1
  29. //cout << j <<" " << counterSteps <<" \n";
  30. }
  31. if (pointX + b <= n && xSteps > -1) { // (0 + 3), (3 + 2 ), (5 + 1NU),
  32. pointX += b; // 3, 5
  33.  
  34. ++counterSteps; // 2, 3
  35. }
  36. }
  37.  
  38. }
  39. cout << counterSteps;
  40.  
  41. return 0;
  42. }
  43. //https://l...content-available-to-author-only...e.ro/page/2gluma-de-1-aprilie#319648
Success #stdin #stdout 0.01s 5316KB
stdin
5 5 
2 3 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 
stdout
3