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.  
  17. int pointY = 0, pointX = 0;; // 1 + 3 = 4.
  18. for (int i = 1; i <= n; ++i) {
  19.  
  20. for (int j = 1; j <= m; ++j) {
  21.  
  22. if (pointY <= n && ySteps != 0) {
  23. pointY = 1 + ySteps;
  24. --ySteps;
  25. ++counterSteps;
  26. //cout << j <<" " << counterSteps <<" \n";
  27. }
  28. if (pointX <= n && xSteps != 0 && ySteps == 0) {
  29. pointX = 1 + xSteps;
  30. ++counterSteps;
  31. --xSteps;
  32. }
  33. }
  34.  
  35. }
  36. cout << counterSteps;
  37.  
  38. return 0;
  39. }
  40. //https://l...content-available-to-author-only...e.ro/page/2gluma-de-1-aprilie#319648
Success #stdin #stdout 0.01s 5284KB
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
5