|

General

# Author Problem Lang Verdict Time Memory Sent Judged
263006010 Practice:
greentree888
1519C - 28 C++20 (GCC 13-64) Accepted 171 ms 8960 KB 2024-05-28 14:58:23 2024-05-28 14:58:23
→ Source
#include<bits/stdc++.h>
using namespace std;
// OM NAMAH SHIVAY

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops,O3")

#define endl "\n"
#define int long long

// int dx[4]={-1,0,1,0};
// int dy[4]={0,1,0,-1};

// int dx[8]={0,-1,-1,-1,0,1,1,1};
// int dy[8]={1,1,0,-1,-1,-1,0,1};

const int N = 200200;
const int mod = 1e9+7;
using ii = pair<int,int>;

//write on copy

void solver(){
int n;cin>>n;
vector<int>uni(n+1),ss(n+1);

vector<vector<int>>mp(n+1);

for(int i=1;i<=n;i++) cin>>uni[i];

for(int i=1;i<=n;i++) cin>>ss[i];

for(int i=1;i<=n;i++)
{
mp[uni[i]].push_back(ss[i]);
}

for(auto &v:mp)
{
sort(rbegin(v),rend(v));
}

for(auto &v:mp)
{
for(int i=1;i<v.size();i++)
{
v[i]+=v[i-1];
}
}

int flg=1;

vector<int>ans(n+1);

for(auto &v:mp)
{
for(int i=1;i<=n;i++)
{
int sz = v.size();

if(sz<i)
{
continue;
}

int cnt = sz/i;

int ii = cnt*i;

ans[i]+=v[ii-1];
}
}

for(int i=1;i<=n;i++)
{
cout<<ans[i]<<" ";
}

cout<<endl;

}

signed main()
{
IOS
int _t;cin>>_t;while(_t--)
solver();
return 0;
}

#undef int
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?