問題一覧 > 通常問題

No.2999 Long Long Friedrice

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 49
作問者 : friedrice / テスター : 👑 qand
お気に入りにしたユーザー ProblemId : 11657 / 自分の提出
問題文最終更新日: 2024-12-24 07:37:30
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 2024 (順位表) の他の問題:

Story

friedrice-kun is far too short, so he went to a pharmacy to buy a potion that makes him taller.
There, the pharmacy was selling a medicine called "Seganobiiru".

Problem Statement

friedrice-kun's height is initially $1$ cm.
He has $N$ bottles of Seganobiiru.
If the user's height is $A_i$ cm when drinking the $i$-th bottle of Seganobiiru, their height increases by $B_i$ cm.
Otherwise, nothing happens when drinking that bottle of Seganobiiru.
Given that he may drink the $N$ bottles of Seganobiiru in any order, what is the maximum possible height, in cm, of friedrice-kun after drinking all $N$ bottles?

Input

$N$
$A_1\ A_2\ \dots\ A_N$
$B_1\ B_2\ \dots\ B_N$

  • $1 \le N \le 2 \times 10 ^ 3$
  • $1 \le A_i, B_i \le 5 \times 10 ^ 5$
  • All inputs are integers.

    Output

    Output the maximum possible height of friedrice-kun after drinking all $N$ bottles.

    Sample

    Sample 1
    Input
    2
    1 4
    3 2
    Output
    6

    Since friedrice-kun's height is initially $1$ cm, he drinks the $1$-st bottle of Seganobiiru.
    Then his height increases by $3$ cm and becomes $4$ cm.
    After that, when he drinks the $2$-nd bottle of Seganobiiru, his height increases by $2$ cm and becomes $6$ cm.
    His height cannot be made greater than $6$ cm, so output 6.

    Sample 2
    Input
    1
    10
    5
    Output
    1

    Drinking the Seganobiiru does not change friedrice-kun's height, so output 1.

    Sample 3
    Input
    5
    1 1 3 4 7
    2 3 4 2 5
    Output
    12

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