C. Permutation Partitions

C. Permutation Partitions

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a permutation p1,p2,…,pnp1,p2,…,pn of integers from 11 to nn and an integer kk, such that 1≤k≤n1≤k≤n. A permutation means that every number from 11 to nn is contained in pp exactly once.

Let's consider all partitions of this permutation into kk disjoint segments. Formally, a partition is a set of segments {[l1,r1],[l2,r2],…,[lk,rk]}{[l1,r1],[l2,r2],…,[lk,rk]}, such that:

  • 1≤li≤ri≤n1≤li≤ri≤n for all 1≤i≤k1≤i≤k;
  • For all 1≤j≤n1≤j≤n there exists exactly one segment [li,ri][li,ri], such that li≤j≤rili≤j≤ri.

Two partitions are different if there exists a segment that lies in one partition but not the other.

Let's calculate the partition value, defined as ∑i=1kmaxli≤j≤ripj∑i=1kmaxli≤j≤ripj, for all possible partitions of the permutation into kk disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by 998244353998244353.

Input

The first line contains two integers, nn and kk (1≤k≤n≤2000001≤k≤n≤200000) — the size of the given permutation and the number of segments in a partition.

The second line contains nn different integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n) — the given permutation.

Output

Print two integers — the maximum possible partition value over all partitions of the permutation into kk disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo 998244353998244353.

Please note that you should only find the second value modulo 998244353998244353.

Examples

input

Copy

3 2
2 1 3

output

Copy

5 2

input

Copy

5 5
2 1 5 3 4

output

Copy

15 1

input

Copy

7 3
2 7 3 1 5 4 6

output

Copy

18 6

Note

In the first test, for k=2k=2, there exists only two valid partitions: {[1,1],[2,3]}{[1,1],[2,3]} and {[1,2],[3,3]}{[1,2],[3,3]}. For each partition, the partition value is equal to 2+3=52+3=5. So, the maximum possible value is 55 and the number of partitions is 22.

In the third test, for k=3k=3, the partitions with the maximum possible partition value are {[1,2],[3,5],[6,7]}{[1,2],[3,5],[6,7]}, {[1,3],[4,5],[6,7]}{[1,3],[4,5],[6,7]}, {[1,4],[5,5],[6,7]}{[1,4],[5,5],[6,7]}, {[1,2],[3,6],[7,7]}{[1,2],[3,6],[7,7]}, {[1,3],[4,6],[7,7]}{[1,3],[4,6],[7,7]}, {[1,4],[5,6],[7,7]}{[1,4],[5,6],[7,7]}. For all of them, the partition value is equal to 7+5+6=187+5+6=18.

The partition {[1,2],[3,4],[5,7]}{[1,2],[3,4],[5,7]}, however, has the partition value 7+3+6=167+3+6=16. This is not the maximum possible value, so we don't count it.

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
int n,k,x;
ll ans=1,sum,p=-1;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>=n-k+1)
        {
            sum+=x;
            if(p!=-1)
            {
                ans=ans*(i-p)%mod;
            }
            p=i;
        }
    }
    printf("%lld %lld\n",sum,ans);

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值