Log inSign up
Problems / B039

Members who get seeds

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

Statement

A community garden club wants to hand out all S of its seeds to its members. Two rules have to be kept while handing them out.

One is that a member who receives seeds receives at least one. The other is that no two members receive the same number of seeds. Not one seed is kept back, so every seed is handed out.

The aim is to reach as many members as possible while keeping these rules.

For example, suppose there are S=6 seeds. The ways to hand them out are the following.

Amounts handed outMembers who receive
61
1, 52
2, 42
1, 2, 33

Splitting them into 1, 2 and 3 reaches three members. Reaching four members calls for four different amounts, and even the smallest four take 1 + 2 + 3 + 4 = 10 seeds, so 6 seeds fall short. The answer in this case is therefore 3.

Now look at the case of S=5 seeds. Reaching three members takes at least 1 + 2 + 3 = 6 seeds, and only 5 are at hand, so it cannot be done. Splitting them into 1 and 4 reaches two members, so the answer is 2.

SSplit that reaches the most membersAnswer
111
221
31, 22
51, 42
61, 2, 33

Working out how far the sum has to run shows the rule. Giving k members amounts that differ from one another takes at least 1 + 2 + ... + k seeds. The largest k whose sum is less than or equal to S is the answer. Piling the seeds left over onto the member who receives the most keeps every amount different. In the case of S=5 and k=2, splitting into 1 and 2 leaves 2 seeds over, so those 2 go onto the back and the split becomes 1 and 4.

Given the number of seeds S, write a program that finds the largest number of members who can receive seeds.

The largest value of S is 4,294,967,295. This value does not fit in a signed 32-bit integer, so the way numbers are handled calls for care. When S is at its largest, the answer is 92,681.

Input and output examples

Example 1

Input

6

Output

3

Example 2

Input

5

Output

2

Example 3

Input

4294967295

Output

92681

Input

  • The first line gives the number of seeds S to hand out. S is a natural number from 1 to 4,294,967,295.

  • The input ends with this one line. The number of members in the club is not given in the input. Take it that there are plenty of members, and work out only how far the number of members who receive seeds can be pushed.

  • S can be given as a value larger than the largest signed 32-bit integer.

Output

  • Print the largest number of members who can receive seeds on the first line.

  • Print one number and then a newline. Do not add any other character or space before or after it.

Requirements

  • Read the input from standard input and write the answer to standard output
  • A member who receives seeds receives at least one. A member with 0 seeds does not count as a member who receives seeds
  • No two members receive the same number of seeds
  • Not one seed is kept back, so every seed is handed out
  • The value to find is not the number of ways to hand the seeds out but the largest number of members who receive them
  • S can go above 4 billion, so adding up with 32-bit integers overflows partway through
  • Grading compares the output with the expected value down to the last character
  • 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.
  • 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
5
2
6
3
4294967295
92681

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 5.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.

1bampal2214ms158 charsPythonLinux / Chrome/158.0.8127.18 / 2코어 / 16GB

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