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 copyN = n, copyM = m;
  16. while (copyN > 1 || copyM > 1) {
  17. if (copyN - xSteps >= 1 && xSteps > 0 ) {
  18. copyN -= xSteps;
  19. ++counterSteps;
  20. }
  21. if (copyM - ySteps >= 1 &&ySteps > 0) {
  22. copyM -= ySteps;
  23. ++counterSteps;
  24. }
  25. if (copyN - xSteps < 1 && copyN >= 1) {
  26. --xSteps;
  27. }
  28. if (copyM - ySteps < 1 && copyM >= 1) {
  29. --ySteps;
  30. }
  31. }
  32. cout << counterSteps;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5320KB
stdin
7 2 
3 1 
4 5 
4 5 
4 5 
4 5 
4 5 
4 5 
4 5 
stdout
3