#include <iostream>
using namespace std;
void print(const int *arr, int n) {
for(int i = 0; i < n; ++i)
cout << arr[i] << " ";
cout << endl;
}
void printIncreasingNumbers(int n, int k) {
if (k == 0) return;
int *startNumArr = new int[k];
for(int i = 0; i < k; ++i) startNumArr[i] = 1 + i;
int curPos = k - 1;
while(curPos >= 0) {
print(startNumArr, k);
while(curPos >= 0) {
++startNumArr[curPos];
if(n - startNumArr[curPos] >= k - curPos - 1) {
for(int i = 1; i <= k - curPos - 1; ++i)
startNumArr[curPos + i] = startNumArr[curPos] + i;
curPos = k - 1; break;
}
else
--curPos;
}
}
delete [] startNumArr;
}
int main() {
int n = 7, k = 3;
printIncreasingNumbers(n, k);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBwcmludChjb25zdCBpbnQgKmFyciwgaW50IG4pIHsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyArK2kpCgkJY291dCA8PCBhcnJbaV0gPDwgIiAiOwoJY291dCA8PCBlbmRsOwp9Cgp2b2lkIHByaW50SW5jcmVhc2luZ051bWJlcnMoaW50IG4sIGludCBrKSB7CglpZiAoayA9PSAwKSByZXR1cm47CglpbnQgKnN0YXJ0TnVtQXJyID0gbmV3IGludFtrXTsKCWZvcihpbnQgaSA9IDA7IGkgPCBrOyArK2kpIHN0YXJ0TnVtQXJyW2ldID0gMSArIGk7CgkKCWludCBjdXJQb3MgPSBrIC0gMTsKCXdoaWxlKGN1clBvcyA+PSAwKSB7CgkJcHJpbnQoc3RhcnROdW1BcnIsIGspOwoJCXdoaWxlKGN1clBvcyA+PSAwKSB7CgkJCSsrc3RhcnROdW1BcnJbY3VyUG9zXTsKCQkJaWYobiAtIHN0YXJ0TnVtQXJyW2N1clBvc10gPj0gayAtIGN1clBvcyAtIDEpIHsKCQkJCWZvcihpbnQgaSA9IDE7IGkgPD0gayAtIGN1clBvcyAtIDE7ICsraSkKCQkJCQlzdGFydE51bUFycltjdXJQb3MgKyBpXSA9IHN0YXJ0TnVtQXJyW2N1clBvc10gKyBpOwoJCQkJY3VyUG9zID0gayAtIDE7IGJyZWFrOwoJCQl9CgkJCWVsc2UKCQkJCS0tY3VyUG9zOwoJCX0KCX0KCWRlbGV0ZSBbXSBzdGFydE51bUFycjsKfQoKaW50IG1haW4oKSB7CglpbnQgbiA9IDcsIGsgPSAzOwoJcHJpbnRJbmNyZWFzaW5nTnVtYmVycyhuLCBrKTsKCXJldHVybiAwOwp9