1326C. Permutation Partitions - Codeforces Solution C++

  Problem Link : 1326C. Permutation Partitions 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define m 998244353 

int main()
{
	ll n,k;
	cin>>n>>k;

	ll p[n];
	for(ll i=0;i<n;i++)
		cin>>p[i];

	ll ans=1;
	ll i=0;


	while(i<n && p[i]<=n-k)
		i++;
    ll val=0;
	while(i<n)
	{
		int j=i+1;
		while(j<n && p[j]<=n-k)
			j++;
        if(j==n)
            break;
            
		ans=(ans*(j-i)%m)%m;
		i=j;
	//	cout<<i<<endl;
	}
	
	val=(n*(n+1))/2;
	ll vk=n-k;
	val-=((vk)*(vk+1))/2;

	cout<<val<<" "<<ans;







}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!