P16932 Monsters

Background

:::info[Problem Background] After passing through the antechamber, the inside of the "Falling Star Archive" was even quieter than expected. The towering dome was hidden in the dimness. Rows upon rows of ancient bookshelves stretched into the depths on all sides, like countless silent walls standing still. The air carried a mixed smell of old paper, stone dust, and faint magic. Footsteps landing on the black stone floor would be dragged into long echoes by the empty hall. Many crystal lamps were embedded between the walls and pillars, most already faded. Only a few still held a weak glow, lighting this vast space that almost had no end in sight like the bottom of the water at dusk. "It just feels... more uncomfortable here than outside." Stark lowered his voice, his hand already gripping his weapon tightly. "Yeah." Fern nodded lightly. "The magic is too dense, and it’s messy." Frieren said nothing. She only raised her head and looked deeper into the hall. There stood a gigantic stone gate. Complex and ancient patterns were carved into its frame. From behind the gate came a very low pulse, like a heartbeat sealed in the deepest part of time—slow, yet never truly stopping. And at the moment the three stepped into the central hall, the entire archive suddenly trembled once. It was not violent, but it made the already silent air tighten instantly. In the next moment, on the platform ahead, a pitch-black shadow slowly stood up. It had almost blended into the surrounding stone wall before this. Only now did Fern see clearly: it was not just a statue, but a monster guarding the depths of the archive. Its body was abnormally tall, as if stitched together from black metal and dead bones. An dark-red core was embedded in its chest, beating slowly. Several long bone spines extended from its shoulders and back, like wings broken and then regrown. The most unpleasant part was its face without complete features—only two deep, cold lights burning where its eyes should have been. "Is it the archive’s guardian...?" Fern whispered. "No." Frieren looked at it, her expression sinking a little. "It’s a monster that has taken this place. It has probably treated this area as its nest." As soon as she finished speaking, the monster moved. There was no warning, and no roar. It simply stepped forward once, and the flow of magic in the entire hall was suddenly twisted as if by an invisible hand. In the next instant, several black impacts pressed in from all directions. Fine cracks burst open on the surface of the stone pillars, and scorched marks were torn into the floor. Stark almost instinctively raised his weapon to block in front, but he was still pushed back several steps by the aftershock. "Fall back." Frieren said calmly, already raising her staff. A dazzling magic light spread in front of her. Several layers of barriers and attack formations took shape almost at the same time, precisely cutting off the approaching black impacts. The roar echoed again and again through the hall. Interwoven light and shadow dyed the tall bookshelves, stone pillars, and dome into flickering colors. Frieren was not that far from the monster, but the surging magic between them had already become a storm that no one could easily cross. Fern gritted her teeth and immediately cast ordinary attack magic as well. Several mana bullets slipped through the gaps Frieren left and accurately blasted the monster’s flank. However, the other side only raised its hand slightly, and a black barrier swallowed all the attacks, leaving not even a ripple. "It’s useless..." Her breathing stalled slightly. "It’s constantly absorbing the scattered magic around it." Frieren’s voice was still calm. "Don’t use attacks that are too spread out. Focus them." "Understood!" Even so, the situation still did not change right away. That monster was shockingly strong. It was not in a hurry to close in. It simply held its ground ahead, using almost flawless defense and an overwhelming amount of magic to directly stalemate Frieren. Each time the formations collided, the hall would tremble once. Each brief gap would immediately be filled by new offense and defense. Time felt especially long, and even breathing began to grow heavy. Stark tried several times to break in from the side, but each time he was forced back by the impact the monster raised. Fern could only keep retreating, searching for barely stable footing between the stone pillars and the shattered floor. She raised her hand to open a barrier. In the next moment, a black beam slammed head-on into it, numbing her arm and making her feet slide backward uncontrollably. Too strong. This was not the kind of battle where you could slowly look for chances. The density of the opponent’s formations, the total amount of magic, and that merciless pressure all kept surging closer like a tide. Fern gathered magic again, but her chest already ached faintly from continuous casting. Cracks appeared on the surface of her defensive magic. Her ears were filled with roaring and shattering echoes. Even her vision was torn into pieces by flying stone dust and strong light. She stepped back, and her heel hit a broken stone base. There was no more room to retreat. Ahead, Frieren was still fighting the monster head-on. But even she could not fully suppress it for the moment. This rare stalemate made Fern realize clearly for the first time—if she could not hold on, the situation would collapse in an instant. Another black impact approached. Fern clenched her teeth, almost instinctively trying to draw on the remaining magic in her body. But that power had been squeezed too hard, like a spring about to run dry, unable to respond smoothly no matter what. Her fingertips turned a little cold, and her breathing became unsteady. At that moment, her hand suddenly touched something hard and warm in the bag at her waist. It was something they had specially prepared before leaving Rozehma Mining Town. Magic power sealed in stone, not yet completely used up, was pulsing through the cloth—weak, yet real. Fern froze for a moment. In the next moment, it was as if she finally grabbed an answer she had forgotten on a dead end road. She widened her eyes, and the words almost burst out— "Ah! A Mana Gathering Stone!" :::

Description

Fern has almost used up all her magic. Initially, Fern can only do her best to activate $1$ Mana Gathering Stone, leaving herself with only $0$ magic points. At the beginning of each second, Fern can recover magic in the following order: - Activate some Mana Gathering Stones. Each stone costs $x$ magic points from herself. - Each activated Mana Gathering Stone she owns restores $y$ magic points to Fern. - Stop activating some Mana Gathering Stones. Each stone stopped can refund $z$ magic points to Fern. Fern needs to restore as much magic as possible. She wants to know: if she wants her magic to be at least $n$ points, what is the minimum number of seconds needed? In particular: - The current moment is the beginning of the $1$-st second. - If by the end of the $1$-st second, Fern’s magic is already at least $n$, then the answer is $1$. - You must ensure that at any time, Fern’s magic is non-negative.

Input Format

Input one line containing four integers $n, x, y, z(1 \leq n, x, y, z \leq 10^{6})$, representing respectively the magic Fern needs, the magic cost to activate one Mana Gathering Stone, the magic restored per second by each activated stone, and the magic refunded by stopping one stone.

Output Format

Output one integer, the minimum number of seconds.

Explanation/Hint

In the first second, the $1$ activated Mana Gathering Stone creates $3$ magic points for Fern, leaving $3$ magic points; in the second second, the $1$ activated Mana Gathering Stone creates $3$ magic points for Fern, leaving $6$ magic points; in the third second, the $1$ activated Mana Gathering Stone creates $3$ magic points for Fern, leaving $9$ magic points; in the fourth second, the $1$ activated Mana Gathering Stone creates $3$ magic points for Fern. Fern chooses to stop activating this stone, refunding $8$ magic points, leaving $20$ magic points, which meets the requirement. :::info[Problem Background] --- "Saved!" Fern almost instinctively gripped that Mana Gathering Stone tightly. Warm, abundant magic quickly poured into her body along her palm. The spell circuits that were almost dried up lit up again, like a weak flame reignited in a night about to go out—small, yet enough to keep going. She panted hard. The hair on her forehead was soaked with sweat, but the wavering in her eyes was finally pressed down again. Still, the situation did not change immediately because of this. Deep in the hall, black impacts and dazzling magic continued to collide. Roars came one after another, echoing for a long time under the towering dome. Frieren still stood at the very front, locked in a stalemate with that powerful monster, and this hard battle was still far from its end. ::: Translated by ChatGPT 5