Codeforces Round #847 (Div. 3) 1790D. Matryoshkas Solution
Problem Link : https://codeforces.com/contest/1790/problem/D
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t ;
- cin >> t ;
- while ( t-- ){
- int n ;
- cin >> n ;
- int a [n+1] ;
- map < int , int > mp ;
- for ( int i = 1 ; i <= n ; i++ ){
- cin >> a[i] ;
- mp[a[i]]++ ;
- }
- int ans = 0 ;
- sort( a + 1 , a + n + 1 ) ;
- for ( int i = 1 ; i <= n ; i++ ){
- int v = a [i] ;
- if ( mp[v] > 0 ){
- ans++;
- while ( mp[v] > 0 ) {
- mp[v]--;
- v++;
- }
- }
- }
- cout << ans << endl;
- }
- return 0 ;
- }
No comments