Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author verytable
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <algorithm>

static const std::string kSpaceChars = " \t\n\r\f\v";

inline std::string& rtrim(std::string& str, const std::string& chars = kSpaceChars) {
    str.erase(str.find_last_not_of(chars) + 1);
    return str;
}

inline std::string& ltrim(std::string& str, const std::string& chars = kSpaceChars) {
    str.erase(0, str.find_first_not_of(chars));
    return str;
}

inline std::string& trim(std::string& str, const std::string& chars = kSpaceChars) {
    return ltrim(rtrim(str, chars), chars);
}


class TaskD {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, w;
        in >> h >> w;

        int n;
        in >> n;

        std::vector<int> row_paint;
        int row = 0;
        int col = 0;
        for (int i = 0; i < n; ++i) {
            int a;
            in >> a;

            while (a > 0) {
                bool left_to_right = (row % 2 == 0);

                if (left_to_right) {
                    int to_paint = std::min(a, w - col);

                    col += to_paint;
                    a -= to_paint;

                    for (int j = 0; j < to_paint; ++j) {
                        row_paint.push_back(i + 1);
                    }

                    if (col == w) {
                        ++row;
                        std::string row_paint_str;
                        for (auto c: row_paint) {
                            row_paint_str += std::to_string(c) + " ";
                        }
                        trim(row_paint_str);
                        out << row_paint_str << '\n';
                        row_paint.clear();
                    }
                } else {
                    int to_paint = std::min(a, col);

                    col -= to_paint;
                    a -= to_paint;

                    for (int j = 0; j < to_paint; ++j) {
                        row_paint.push_back(i + 1);
                    }

                    if (col == 0) {
                        ++row;
                        std::reverse(row_paint.begin(), row_paint.end());
                        std::string row_paint_str;
                        for (auto c: row_paint) {
                            row_paint_str += std::to_string(c) + " ";
                        }
                        trim(row_paint_str);
                        out << row_paint_str << '\n';
                        row_paint.clear();
                    }
                }
            }
        }
    }
};


int main() {
    TaskD solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Compiler output:
a.cc: In member function 'void TaskD::solve(std::istream&, std::ostream&)':
a.cc:39:14: error: 'vector' is not a member of 'std'
   39 |         std::vector<int> row_paint;
      |              ^~~~~~
a.cc:12:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   11 | #include <algorithm>
  +++ |+#include <vector>
   12 | 
a.cc:39:21: error: expected primary-expression before 'int'
   39 |         std::vector<int> row_paint;
      |                     ^~~
a.cc:56:25: error: 'row_paint' was not declared in this scope; did you mean 'to_paint'?
   56 |                         row_paint.push_back(i + 1);
      |                         ^~~~~~~~~
      |                         to_paint
a.cc:62:38: error: 'row_paint' was not declared in this scope; did you mean 'to_paint'?
   62 |                         for (auto c: row_paint) {
      |                                      ^~~~~~~~~
      |                                      to_paint
a.cc:67:25: error: 'row_paint' was not declared in this scope; did you mean 'to_paint'?
   67 |                         row_paint.clear();
      |                         ^~~~~~~~~
      |                         to_paint
a.cc:76:25: error: 'row_paint' was not declared in this scope; did you mean 'to_paint'?
   76 |                         row_paint.push_back(i + 1);
      |                         ^~~~~~~~~
      |                         to_paint
a.cc:81:38: error: 'row_paint' was not declared in this scope; did you mean 'to_paint'?
   81 |                         std::reverse(row_paint.begin(), row_paint.end());
      |                                      ^~~~~~~~~
      |                                      to_paint