Max (Sum - Max)

AtCoder
IDabc348_g
Time2000ms
Memory256MB
Difficulty
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 $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$. ## Constraints * $1 \leq N \leq 2 \times 10^5$ * $-10^9 \leq A_i \leq 10^9$ * $-2 \times 10^{14} \leq B_i \leq 2 \times 10^{14}$ ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_N$ $B_N$ [samples]
Samples
Input #1
3
4 1
5 6
3 2
Output #1
3
5
6

The following choices are optimal.

*   $k = 1$: $S = {1}$
*   $k = 2$: $S = {1, 3}$
*   $k = 3$: $S = {1, 2, 3}$
Input #2
2
0 1
0 1
Output #2
\-1
-1
Input #3
6
9 7
2 4
7 1
-1000 0
3 4
8 5
Output #3
6
10
17
20
22
-978
API Response (JSON)
{
  "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 ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments