Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define M 1000000007
- #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define PI 3.14159265
- #define pb push_back
- #define LLMX LONG_LONG_MAX
- #define LLMN LONG_LONG_MIN
- #define double long double
- vector < int > arr ;
- set < int > st ;
- vector < int > graph[3003] ;
- int n , m , k;
- map < pair < pair < int , int > , int > , int > dp ;
- bool comp( vector < int > &a , vector < int > &b)
- {
- if( (signed)a.size() > (signed)b.size())
- return true ;
- else
- return false ;
- }
- vector < int > university[200005] ;
- signed main()
- {
- fastio ;
- int T ;
- cin >> T ;
- while( T--)
- {
- st.clear() ;
- cin >> n ;
- vector < int > u , s;
- for(int x = 1 ; x <= n ; x++)
- {
- int t;
- cin >> t ;
- u.pb(t) ;
- st.insert(t) ;
- }
- for(int x = 1 ; x <= n ; x++)
- {
- int t;
- cin >> t ;
- s.pb(t) ;
- }
- for(auto it = st.begin() ; it != st.end() ; it++)
- university[*it].clear() ;
- for(int x = 0 ; x < n ; x++)
- university[u[x]].pb(s[x]) ;
- for(auto it = st.begin() ; it != st.end() ; it++)
- sort(university[*it].begin() , university[*it].end() , greater < int >()) ;
- vector < vector < int > > temp ;
- for(auto it = st.begin() ; it != st.end() ; it++)
- {
- int sum = 0 ;
- for(int x = 0 ; x < university[*it].size() ; x++)
- {
- sum = sum + university[*it][x] ;
- university[*it][x] = sum ;
- }
- }
- int maxi = LLMN ;
- for(auto it = st.begin() ; it != st.end() ; it++)
- {
- if( university[*it].size() > maxi)
- maxi = university[*it].size() ;
- temp.pb(university[*it]) ;
- }
- sort( temp.begin() , temp.end() , comp) ;
- for(int k = 1 ; k <= n ; k++)
- {
- if( k > maxi)
- {
- cout << "0 " ;
- continue ;
- }
- int sum = 0 ;
- for(auto it = temp.begin() ; it != temp.end() ; it++)
- {
- if( (*it).size() < k)
- break ;
- for(int x = k -1 ; x < (signed)(*it).size() ; x = x + k )
- {
- if( x + k >= (*it).size())
- {
- sum = sum + (*it)[x] ;
- }
- }
- }
- cout << sum << " " ;
- }
- cout << "\n" ;
- }
- }
Add Comment
Please, Sign In to add comment