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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.