Codeforces Global Round 7 1326C - Permutation Partitions Solution
Problem Link : https://codeforces.com/problemset/problem/1326/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- const int mod = 998244353 ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n , k , x ;
- cin >> n >> k ;
- int pre_value = - 1 ;
- long long ans = 1 , sum = 0 ;
- for ( int i = 1 ; i <= n ; i++){
- cin >> x ;
- if (x >= n - k + 1){
- if (pre_value != -1){
- ans = 1LL* ans * (i - pre_value) % mod ;
- }
- sum += x ;
- pre_value = i ;
- }
- }
- cout <<sum<<" "<< ans <<'\n';
- return 0 ;
- }
No comments