USACOs Arithmetic Progression
Faster searching

Suppose you have an array filled with either 1 and 0, and you are trying to search for a consecutive sequence of twenty 1's in a row.  The way you are doing it is like this:

111111111111111100001111111110111011111111
^               ^
|...............|
start here      end here  length = 15, not long enough, so move on

Next iteration:

111111111111111100001111111110111011111111
 ^              ^
 |..............|
 start here     end here  length = 14, not long enough, so move on

Next iteration:

111111111111111100001111111110111011111111
  ^             ^
  |.............|
  start here    end here  length = 13, not long enough, so move on


As you can imagine, the above algorithm is not very efficient because you are wasting time looking at the same array values over and over again.  The above can take up to \$O(M*N)\$ time, where \$M\$ is the length of the string and \$N\$ is the length of the sequence you are searching for.

Instead of restarting your search from the next index, you should be restarting your search from just past the zero you found:

111111111111111100001111111110111011111111
^               ^
|...............|
start here      end here  length = 15, not long enough, so move on

Next iteration:

111111111111111100001111111110111011111111
                 ^
                 |
                 Restart here, not back there


By doing this, the search now only takes \$O(M)\$ time.  You could do even better by mimicking the Boyer Moore string search algorithm and skipping to the end and searching backwards, like this:

111111111111111101111111111110111011111111
^
|
start here

111111111111111101111111111110111011111111
                   ^
                   |
                   jump 19 spots ahead and search backwards

111111111111111101111111111110111011111111
                ^
                |
                Found a zero here

111111111111111101111111111110111011111111
                 ^
                 |
                 Restart here


This is still an \$O(M)\$ algorithm in the worst case, but it can be as fast as \$O(M/N)\$ in the best case (an array filled with all 0s).

Loop rearrangement

The way you have set up your loops does not lend itself to doing the faster searching methods.  You will need to rearrange your loops in order to be able to restart your searches properly.  I suggest you move your x loop from being the innermost loop to being the outermost loop.  Then you may find that the two other loops collapse into a single search loop.