from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,K = map(int,input().split()) C = list(map(int,input().split())) D = list(map(int,input().split())) mod = 998244353 dp = [-1]*(K+2) dp[0] = 0 for i in range(N): c,d = C[i],D[i] for j in range(K): if dp[j]!=-1: dp[min(K+1,j+c)] = max(dp[min(K+1,j+c)],dp[j]+d) e = [[] for _ in range(K+2)] for i in range(N): c,d = C[i],D[i] for j in range(K): k = min(K+1,j+c) if dp[k]-dp[j]==d: e[j].append(k) val = [0]*(K+2) # print(dp) val[0] = 1 for i in range(K): for j in e[i]: val[j] += val[i] val[j] %= mod M = max(dp[:K+1]) ans = 0 for j in range(K+1): if dp[j]==M: ans += val[j] ans %= mod print(M) print(ans)