Log inSign up
Problems / B057

Choosing saplings

200 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A nursery has N saplings numbered 1 through N. The keeper picks M of them and moves them to a flower bed.

Once they are in the flower bed, which sapling went into which spot is not kept in the record. All the record keeps is the numbers of the saplings that were picked. Two choices with the same saplings therefore count as the same case, whichever spots they went into.

Write a program that prints every case in which the keeper can pick saplings, in lexicographic order. Each case is written with the numbers of the picked saplings in ascending order. Lexicographic order means that the case whose first written number is smaller comes first, and when those numbers are equal, the case whose second number is smaller comes first.

For example, suppose M=2 of the N=4 saplings are picked. There are 6 cases that can be picked, and listing them in lexicographic order gives the following table.

CaseSmaller numberLarger number
112
213
314
423
524
634

Only the numbers of the picked saplings are kept and the spots are not looked at, so picking 1 and 2 and picking 2 and 1 are the same case. The table therefore holds the one entry 1, 2 and nothing more.

Picking three saplings is counted the same way. Picking M=3 of N=5 saplings gives 10 cases, as in the following table.

CaseFirst numberSecond numberThird number
1123
2124
3125
4134
5135
6145
7234
8235
9245
10345

Looking at the table, the numbers in each case grow from left to right. Within one case a number never goes down. Only once every case whose first number is 1 has been written down does a case whose first number is 2 come up.

If M=N, every sapling is moved, so only one case is possible. If M=1, on the other hand, only one sapling is picked, so there are N cases.

Input and Output Examples

Example 1

Input

4 2

Output

1 2
1 3
1 4
2 3
2 4
3 4

Example 2

Input

1 1

Output

1

Example 3

Input

3 3

Output

1 2 3

Input

  • The number of saplings N in the nursery is given first as a natural number. N is a natural number from 1 to 8.

  • The number of saplings M to move to the flower bed then comes on the same line, separated by a space. M is a natural number from 1 to 8, and it is not larger than N, the number of saplings.

  • The input is therefore one line, and that line holds two natural numbers separated by one space.

Output

  • Print every case in which the saplings can be picked in lexicographic order, one per line. One line holds the M picked sapling numbers in ascending order. On top of that, The last three characters of the output are therefore a space, a newline and a newline, in that order. When a line holds more than one value, the values are separated by a single space.

Requirements

  • A sapling that has been picked is not picked again
  • Choices with the same saplings count as the same case, so print each case only once
  • Write the numbers of each case in ascending order
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
1 1
1
3 3
1 2 3
4 2
1 2
1 3
1 4
2 3
2 4
3 4

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal228ms215 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.