問題一覧 > 通常問題

No.3413 Hasty Luku-kun

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 32
作問者 : ルク / テスター : yuusaan AwashAmityOak kazuppa
お気に入りにしたユーザー ProblemId : 12880 / 自分の提出
問題文最終更新日: 2025-12-19 23:04:24
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2025 (順位表) の他の問題:

Story

kazuppa-kun, Awash-kun, Yu~-san, and Luku-kun are preparing for a Christmas party.

Luku-kun is in charge of being 🎅Santa Claus.

With 🎄Christmas approaching, Santa Claus Luku-kun was preparing sweets to hand out to the children.

Then, in order to become a better Santa Claus, Luku-kun invented a truly wonderful machine that can change the happiness of a candy.

At that point, Luku-kun suddenly came up with the following question.

Luku: "I want to give the children as many different kinds of happiness as possible~"

Luku: "If I choose some candies from the ones I have and the ones I made, and add up their happiness, what is the maximum happiness that cannot be made?"

After some thought, Luku-kun decided to formalize this question.

Problem Statement

Luku-kun has many 🍭candies to hand out to the children.

All of these candies have value $1$ and happiness $X$.

Luku-kun has developed $N$ types of machines of strength $d$ that can change happiness.

A machine of type $i (1 \le i \le N)$ can perform the following operation.

  • When a candy of value $i$ is put in, the candy changes as follows.
    • Its value changes from $i$ to $i+1$.
    • Letting $k$ be the happiness of the candy put in, its happiness changes from $k$ to $k+d$.
  • When a candy whose value is not $i$ is put in, nothing happens and the candy put in is returned.

You are given $Q$ queries, so solve the following problem.

In the $i$-th query, starting from Luku-kun's many candies of value $1$ and happiness $X_i$, use the $N_i$ types of machines of strength $d_i$ any number of times and in any order. Choose any number ($0$ is allowed) of arbitrary candies that can be produced this way, and find the maximum integer that cannot be represented as the sum of their happiness.

However, if there is a way of choosing such that the sum of happiness that cannot be made exceeds $10^{1000}$, output inf.

Input

$Q$
$X_1\ N_1\ d_1$
$X_2\ N_2\ d_2$
$\vdots$
$X_Q\ N_Q\ d_Q$

Constraints

  • $1 \le Q \le 2 \times 10^5$
  • $1 \le X_i, N_i, d_i \le 10^9 (1 \le i \le Q)$

Output

Output the answer to each query, separated by newlines.

Sample

Sample 1
Input
3
2 2 5
2 1 2
1 1000000000 1
Output
5
inf
-1

In the $1$st query, for example, combining $3$ candies of value $1$ and happiness $2$ makes a candy of happiness $6$.

Also, putting a candy of value $1$ into machine $1$ makes a candy of value $2$ and happiness $2+5=7$.

Beyond this as well, candies of any happiness can be made by combining them appropriately.

On the other hand, a total happiness of $5$ cannot be achieved by any choice of candies, so the answer is $5$.

In the $2$nd query, the happiness of the candies that can be made is $2$ or $4$, and no combination of them can have an odd sum. Therefore, output inf.

In the $3$rd query, note that choosing no candies at all is allowed.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。