atcoder#ABC216F. [ABC216F] Max Sum Counting

[ABC216F] Max Sum Counting

Score : 500500 points

Problem Statement

Given are sequences of NN integers each: A=(A1,,AN)A = (A_1, \dots, A_N) and B=(B1,,BN)B = (B_1, \dots, B_N). Find the number of non-empty subsets SS of {1,2,,N}\{1,2,\ldots,N\} that satisfy the following condition:

  • maxiSAiiSBi\max_{i \in S} A_i \geq \sum_{i \in S} B_i.

Since the count can be enormous, print it modulo 998244353998244353.

Constraints

  • 1N50001 \leq N \leq 5000
  • 1Ai,Bi50001 \leq A_i,B_i \leq 5000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

Output

Print the number of subsets SS that satisfy the condition in the Problem Statement, modulo 998244353998244353.

2
3 1
1 2
2

{1,2,,N}\{1,2,\ldots,N\} has three subsets: {1}\{1\}, {2}\{2\}, and {1,2}\{1,2\}.

  • For S={1}S=\{1\}, we have maxiSAi=3\max_{i \in S} A_i=3 and iSBi=1\sum_{i \in S} B_i=1.
  • For S={2}S=\{2\}, we have maxiSAi=1\max_{i \in S} A_i=1 and iSBi=2\sum_{i \in S} B_i=2.
  • For S={1,2}S=\{1,2\}, we have maxiSAi=3\max_{i \in S} A_i=3 and iSBi=3\sum_{i \in S} B_i=3.

Thus, the condition maxiSAiiSBi\max_{i \in S} A_i \geq \sum_{i \in S} B_i is satisfied by two subsets: {1}\{1\} and {1,2}\{1,2\}.

2
1 1
2 2
0

There may be no subsets that satisfy the condition.

20
1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247
4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017
476