Check if is it possible to get to a point that is presented by a number
General remarks

This

using namespace std;


is considered bad practice, see for example Why is “using namespace std” considered bad practice? on Stack Overflow.

Consistent indenting and spacing increases the legibility of the code.

Use curly braces for if/else blocks even if they consist only of a single statement.

Enable all compiler warnings and fix them, such as

std::cout&lt;&lt;x1&lt;&lt;" "&lt;&lt;y1;
// Variable 'x1' may be uninitialized when used here
// Variable 'y1' may be uninitialized when used here


Choose better variable names: 

bool flag = false;


does not indicate what the flag is used for.

Testing boolean values: This may be opinion-based, but I prefer

if (!flag) { ... }


over 

if (flag == false) { ... }


The return statement in main() is optional, and can be omitted.

Program structure

Separating the actual computation from the I/O makes the main method short, increases the clarity of the program, and allows you to add unit tests easily. In addition, you can “early return” from the function if a solution is found, so that the flag, x1, y1 variables becomes obsolete.

As of C++17 you can return an optional which contains a value (the solution as a pair) or not.

With these suggestions, the program could look like this:

#include &lt;iostream&gt;
#include &lt;optional&gt;

std::optional&lt;std::pair&lt;int, int&gt;&gt; solveSteps(int x, int y, int n) {
    for (int i = 0; i &lt;= n; i++) {
        for (int j = 0; j &lt;= n; j++) {
            if (x * i + j * y == n) {
                // Return solution:
                return std::make_optional(std::make_pair(i, j));
            }
        }
    }
    // No solution found:
    return std::nullopt;
}

int main()
{
    int n, x, y;
    std::cin &gt;&gt; n &gt;&gt; x &gt;&gt; y;

    auto solution = solveSteps(x, y, n);
    if (solution) {
        std::cout &lt;&lt; solution-&gt;first &lt;&lt; " " &lt;&lt; solution-&gt;second &lt;&lt; "\n";
    } else {
        std::cout &lt;&lt; "-1\n";
    }
}


Increasing the performance

First you can increase i and j in steps of x and y, respectively. That reduces the number of iterations and save the multiplications:

std::optional&lt;std::pair&lt;int, int&gt;&gt; solveSteps(int x, int y, int n) {
    for (int i = 0; i &lt;= n; i += x) {
        for (int j = 0; j &lt;= n; j += y) {
            if (i + j == n) {
                // Return solution:
                return std::make_optional(std::make_pair(i/x, j/y));
            }
        }
    }
    // No solution found:
    return std::nullopt;
}


The next improvement is to get rid of the inner loop: After moving  i steps of width  x you only have to check if the remaining distance is a multiple of y:

std::optional&lt;std::pair&lt;int, int&gt;&gt; solveSteps(int x, int y, int n) {
    for (int i = 0; i &lt;= n; i += x) {
        if ((n - i) % y == 0) {
            // Return solution:
            return std::make_optional(std::make_pair(i/x, (n-i)/y));
        }
    }
    // No solution found:
    return std::nullopt;
}


Another improvement would be to check if y &gt; x. In that case it is more efficient to iterate in steps of width  y and check if the remaining distance is a multiple of x. 

Mathematics

Some final remarks on how this can be solved mathematically, with links for further reading.

What you are looking for is solution \$ (i, j) \$ to the equation
$$
 n = i x + j y
$$
with non-negative integers \$ i, j \$. This is related to Bézout's identity. In particular, a solution can only exist if  \$ n  \$ is a multiple of the greatest common divisor  \$ \gcd(x, y)  \$, which is efficiently determined with the euclidean algorithm. In that case it is easy to check if a solution with non-negative numbers exists, compare e.g. Finding positive Bézout coefficients on Mathematics Stack Exchange.