Codeforces Global Round 7 1326C - Permutation Partitions Solution


 

 Problem Link : https://codeforces.com/problemset/problem/1326/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int mod = 998244353 ;
  5. int32_t main() {
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. int n , k , x ;
  9. cin >> n >> k ;
  10. int pre_value = - 1 ;
  11. long long ans = 1 , sum = 0 ;
  12. for ( int i = 1 ; i <= n ; i++){
  13. cin >> x ;
  14. if (x >= n - k + 1){
  15. if (pre_value != -1){
  16. ans = 1LL* ans * (i - pre_value) % mod ;
  17. }
  18. sum += x ;
  19. pre_value = i ;
  20. }
  21. }
  22. cout <<sum<<" "<< ans <<'\n';
  23. return 0 ;
  24. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.