Sum of Min

AtCoder
IDabc438_g
Time2000ms
Memory256MB
Difficulty
You are given integers $N,M,K$, a length-$N$ integer sequence $A=(A_0,A_1,\ldots,A_{N-1})$, and a length-$M$ integer sequence $B=(B_0,B_1,\ldots,B_{M-1})$. Note that the indices start from $0$. Find $\displaystyle\sum_{i=0}^{K-1} \min(A_{i\bmod N}, B_{i \bmod M}) $ , modulo $998244353$. ## Constraints * $1\le N,M\le 2\times 10^5$ * $1\le K\le 10^{18}$ * $1\le A_i,B_i\le 10^9$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $M$ $K$ $A_0$ $A_1$ $\ldots$ $A_{N-1}$ $B_0$ $B_1$ $\ldots$ $B_{M-1}$ [samples]
Samples
Input #1
3 2 5
3 1 4
1 5
Output #1
7

The desired value is $\min(3,1)+\min(1,5)+\min(4,1)+\min(3,5)+\min(1,1)=7$.
Input #2
4 4 27
6 1 10 42
87 6 21 33
Output #2
317
Input #3
5 7 583272014892537201
763832259 547096173 408327452 685495693 212251318
850800766 845647066 240229336 648345577 691868483 740301913 740485849
Output #3
931208848

Compute modulo $998244353$.
API Response (JSON)
{
  "problem": {
    "name": "Sum of Min",
    "description": {
      "content": "You are given integers $N,M,K$, a length-$N$ integer sequence $A=(A_0,A_1,\\ldots,A_{N-1})$, and a length-$M$ integer sequence $B=(B_0,B_1,\\ldots,B_{M-1})$. Note that the indices start from $0$. Find $",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc438_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integers $N,M,K$, a length-$N$ integer sequence $A=(A_0,A_1,\\ldots,A_{N-1})$, and a length-$M$ integer sequence $B=(B_0,B_1,\\ldots,B_{M-1})$. Note that the indices start from $0$.\nFind $...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments