Language: C++

#include<iostream>
#include<vector>
using namespace std;

const int NIL = -1;
const int INF = 12000;
enum {UNDER, ABOVE};

int time;

class Car {
public:
    int id, arrive, sojourn;
    int leave;
    Car(int i, int a, int s) :id(i), arrive(a), sojourn(s) {}
    void park(int t) {leave = t + sojourn;}
    int remain() {return leave - time;}
};

int main() {
    int n, m;
    while(cin >> m >> n, m | n) {
        vector<vector<int>> parking(2, vector<int>(m, NIL));
        vector<Car> car;
        for(int i = 0; i < n; ++i) {
            int t;
            cin >> t;
            car.push_back(Car(i, i * 10, t));
        }

        int head = 0;
        vector<int> answer;
        for(time = 0; answer.size() < n; ++time) {
            // leave
            for(int i = 0; i < m; ++i) {
                int id = parking[UNDER][i];
                if(id == NIL) continue;
                if(car[id].leave > time) continue;
                answer.push_back(id + 1);
                parking[UNDER][i] = parking[ABOVE][i];
                parking[ABOVE][i] = NIL;
            }
            // park
            // empty
            while(head < n && car[head].arrive <= time) {
                bool in = false;
                for(int i = 0; i < m; ++i) {
                    int id = parking[UNDER][i];
                    if(id != NIL) continue;
                    parking[UNDER][i] = head;
                    car[head].park(time);
                    ++head;
                    in = true;
                    break;
                }
                if(!in) break;
            }
            // not empty
            while(head < n && car[head].arrive <= time) {
                int dif1 = INF, target1 = NIL;
                int dif2 = INF, target2 = NIL;
                for(int i = 0; i < m; ++i) {
                    if(parking[ABOVE][i] != NIL) continue;
                    int id = parking[UNDER][i];
                    if(car[id].remain() >= car[head].sojourn) {
                        if(dif1 > car[id].remain() - car[head].sojourn) {
                            dif1 = car[id].remain() - car[head].sojourn;
                            target1 = i;
                        }
                    } else {
                        if(dif2 > car[head].sojourn - car[id].remain()) {
                            dif2 = car[head].sojourn - car[id].remain();
                            target2 = i;
                        }
                    }
                }
                bool in = false;
                if(target1 != NIL) {
                    parking[ABOVE][target1] = parking[UNDER][target1];
                    parking[UNDER][target1] = head;
                    car[head].park(time);
                    ++head;
                    in = true;
                } else if (target2 != NIL) {
                    parking[ABOVE][target2] = parking[UNDER][target2];
                    parking[UNDER][target2] = head;
                    car[head].park(time);
                    ++head;
                    in = true;
                }
                if(!in) break;
            }
        }

        for(int i = 0; i < n; ++i) cout << (i == 0 ? "" : " ") << answer[i];
        cout << endl;
    }
}

Compiler output:
a.cc:9:5: error: 'int time' redeclared as different kind of entity
    9 | int time;
      |     ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In member function 'int Car::remain()':
a.cc:17:32: error: invalid operands of types 'int' and 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} to binary 'operator-'
   17 |     int remain() {return leave - time;}
      |                          ~~~~~ ^ ~~~~
      |                          |       |
      |                          int     time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc: In function 'int main()':
a.cc:33:18: error: assignment of function 'time_t time(time_t*)'
   33 |         for(time = 0; answer.size() < n; ++time) {
      |             ~~~~~^~~
a.cc:33:44: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
   33 |         for(time = 0; answer.size() < n; ++time) {
      |                                            ^~~~
a.cc:33:44: error: lvalue required as increment operand
a.cc:38:34: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   38 |                 if(car[id].leave > time) continue;
a.cc:45:48: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   45 |             while(head < n && car[head].arrive <= time) {
a.cc:51:36: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
   51 |                     car[head].park(time);
      |                                    ^~~~
      |                                    |
      |                                    time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:16:19: note:   initializing argument 1 of 'void Car::park(int)'
   16 |     void park(int t) {leave = t + sojourn;}
      |               ~~~~^
a.cc:59:48: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   59 |             while(head < n && car[head].arrive <= time) {
a.cc:81:36: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
   81 |                     car[head].park(time);
      |                                    ^~~~
      |                                    |
      |                                    time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:16:19: note:   initializing argument 1 of 'void Car::park(int)'
   16 |     void park(int t) {leave = t + sojourn;}
      |               ~~~~^
a.cc:87:36: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
   87 |                     car[head].park(time);
      |                                    ^~~~
      |                                    |
      |                                    time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
a.cc:16:19: note:   initializing argument 1 of 'void Car::park(int)'
   16 |     void park(int t) {leave = t + sojourn;}
      |               ~~~~^