Codeforces Round 1066 (Div. 1 + Div. 2)
F
Git Gud
Codeforces
2400
原题
← EG →
翻译中…
翻译中…

You are an adventurer working for the futuristic corporation RoboCorp. Your current skill level is an integer $s$ in the range $[1, n]$, but you don't know its exact value. Your goal is to reach skill $\geq n$ by completing missions for RoboCorp, but each mission costs precious robocoins.

翻译中…

You can choose missions of any difficulty and any positive integer duration (in hours). However, the cost depends both on the new mission's length, and on how the new mission's difficulty compares to your most recent one.

翻译中…

Let $x$ be the difficulty of your most recent mission. If you want to undertake a new mission of difficulty $y$ and duration $l$:

翻译中…
  • If it is your first mission, or $y \leq x$, the cost is $l$ robocoins.
  • If $y \gt x$, the cost is $1000 + l$ robocoins.
翻译中…

Your skill improves only when you take on a mission whose difficulty exactly matches your current skill:

翻译中…
  • If $y = s$, then your skill increases by $l$.
  • Otherwise, your skill does not change.
翻译中…

After each mission, you still don't know your actual skill value.

翻译中…

You start with $10^6$ robocoins. Find a strategy (a sequence of missions) that does not exceed your budget and guarantees your skill becomes at least $n$, no matter what your initial skill was.

翻译中…

Input

翻译中…

The input contains a single line with an integer $n$ ($n = 4$ or $n = 250\,000$) — the target skill level (that is, by the end, your skill must be $\geq n$).

翻译中…

There are exactly $2$ tests in this problem (including the example). The example has $n = 4$, and the other test has $n = 250\,000$.

翻译中…

Hacks are not allowed in this problem.

翻译中…

Output

翻译中…

In the first line, print a single integer $k$ ($0 \leq k \leq 10^6$) — the number of missions you plan to complete.

翻译中…

Then, print $k$ lines. The $i$-th line must contain two integers $y$ and $l$ ($1 \leq y, l \leq 10^6$) — the difficulty and duration (in hours) of the $i$-th mission, respectively.

翻译中…

Note

翻译中…

In the example, your target skill is $n = 4$. You can use the following strategy:

翻译中…
  • Take a mission of difficulty $y = 1$ and duration $l = 4$. It's your first mission, so you pay $l = 4$ robocoins.
  • Take a mission of difficulty $y = 3$ and duration $l = 1$. The previous mission had difficulty $x = 1$, so since $y \gt x$, you pay $l + 1000 = 1001$ robocoins.
  • Take a mission of difficulty $y = 2$ and duration $l = 1$. Now $x = 3$, and since $y \leq x$, you pay $l = 1$ robocoin.
  • Take a mission of difficulty $y = 3$ and duration $l = 1$. Now $x = 2$, and since $y \gt x$, you pay $l + 1000 = 1001$ robocoins.
翻译中…

In total, you spend $2007$ robocoins, which is within your $10^6$-robocoin budget.

翻译中…

Now we verify that this strategy always works:

翻译中…
  • If your initial skill was $1$, after the first mission it becomes $5$.
  • If your initial skill was $2$, after the third mission it becomes $3$, and after the fourth mission it becomes $4$.
  • If your initial skill was $3$, after the second mission it becomes $4$.
  • If your initial skill was $4$, it stays $4$.
翻译中…

So no matter what your starting skill is, you end with skill $\geq n$.

翻译中…

样例

Input #1
4
Output #1
4
1 4
3 1
2 1
3 1
InputCopy OutputCopy
题目信息
题号
2157F
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
分治
数学
三分

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。