{"problem":{"name":"Max (Sum - Max)","description":{"content":"You are given two integer sequences $A$ and $B$ of length $N$. For $k = 1, 2, \\ldots, N$, solve the following problem: *   Consider choosing $k$ distinct integers between $1$ and $N$, inclusive. Let ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc348_g"},"statements":[{"statement_type":"Markdown","content":"You are given two integer sequences $A$ and $B$ of length $N$. For $k = 1, 2, \\ldots, N$, solve the following problem:\n\n*   Consider choosing $k$ distinct integers between $1$ and $N$, inclusive. Let $S$ be the set of chosen integers. Find the maximum value of $\\displaystyle (\\sum_{i \\in S} A_i) - \\max_{i \\in S} B_i$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2 \\times 10^5$\n*   $-10^9 \\leq A_i \\leq 10^9$\n*   $-2 \\times 10^{14} \\leq B_i \\leq 2 \\times 10^{14}$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$\n$A_2$ $B_2$\n$\\vdots$\n$A_N$ $B_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc348_g","tags":[],"sample_group":[["3\n4 1\n5 6\n3 2","3\n5\n6\n\nThe following choices are optimal.\n\n*   $k = 1$: $S = {1}$\n*   $k = 2$: $S = {1, 3}$\n*   $k = 3$: $S = {1, 2, 3}$"],["2\n0 1\n0 1","\\-1\n-1"],["6\n9 7\n2 4\n7 1\n-1000 0\n3 4\n8 5","6\n10\n17\n20\n22\n-978"]],"created_at":"2026-03-03 11:01:14"}}