#include #include #include using namespace std; int main(void) { int carriageCount, trackCount; while ( (cin >> carriageCount >> trackCount) && ((carriageCount != 0) || (trackCount != 0))) { // read carriage order deque inOrder; deque trackAssign; int* outOrder = new int[carriageCount]; for (int i=0; i> order; inOrder.push_back(order); } vector > tracks; for (int i=0; i()); } bool wasError = false; while (!inOrder.empty()) { int lowestDiff = carriageCount * 2; int lowestDiffTrackIndex = -1; for (int i=0; i 0) && (diff < lowestDiff)) { lowestDiff = diff; lowestDiffTrackIndex = i; } } } if (lowestDiffTrackIndex == -1) { wasError = true; break; } else { //assigning to a track outOrder[inOrder.front() - 1] = (trackCount - lowestDiffTrackIndex); tracks[lowestDiffTrackIndex].push_back(inOrder.front()); trackAssign.push_back(lowestDiffTrackIndex); inOrder.pop_front(); } } if (wasError) { cout << "Transportation failed" << endl; } else { while (!trackAssign.empty()) { cout << (trackCount - trackAssign.front()); trackAssign.pop_front(); if (!trackAssign.empty()) { cout << " "; } } cout << endl; for (int i=0; i