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. int counterSteps = 0, xSteps = x, ySteps = y;
  15. int pointY = 0, pointX = 0;
  16. int a = 0, b = 0;
  17. for (int j = 1; j <= n; ++j) {
  18. //a = 1 + ySteps; // (1 + 1 = 2),
  19. //b = 1 + xSteps; // (1 + 1 = 2),
  20. a += ySteps; // 1, 2, 3, 4, 0
  21. b += xSteps; // 1,2, -> ajunge 0
  22.  
  23. if (pointX + b <= m && xSteps > -1 ) {
  24. pointX += b; // 1, 2 -> nu mai intra ca 2 + 2 > m
  25. ++counterSteps; // 1, 3
  26. }
  27.  
  28. if (pointY + a <= n && ySteps > -1) {
  29. pointY += a; // 1, 2, 5, 9dar ni merge
  30. ++counterSteps;// 2, 4, 5
  31. }
  32.  
  33. if (pointX + b > m) {
  34. --xSteps;// 0
  35. }
  36.  
  37. if (pointY + a > n) {
  38. --ySteps;// 0
  39. }
  40.  
  41. //--ySteps;//
  42. //--xSteps;
  43. }
  44. cout << counterSteps;
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5280KB
stdin
7 2 
1 1 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
1 2 
stdout
4