42902023-03-22 13:28:53horvathabelÓvodacpp17Wrong answer 33/50142ms28080 KiB
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll=long long; 
int main() {
ll n,m;
cin>>n>>m;
vector<ll> db; 
for (int i=0; i<m;i++){
	int z;
	cin>>z;
	db.push_back(z);
}
vector<ll> ak,sir;
vector<int> dbz(m+1);
for (ll i=0; i<n;i++){
	ll x;
	cin>>x;
	x--;
	dbz[x]++;
	ak.push_back(x);
}
for (int i=0; i<n;i++){
	ll x;
	cin>>x;
	sir.push_back(x);
}
priority_queue<pair<ll,pair<ll,ll>>, vector<pair<ll,pair<ll,ll>>>, greater<pair<ll,pair<ll,ll>>>> osszgy; 
vector<priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>>> q(m);
for (int i=0; i<n;i++){
	osszgy.push({sir[i],{ak[i],i}});
}
ll ans=0;
queue<ll> plussz;
int cnt=0; 
for (int i=0; i<n;i++) q[ak[i]].push({sir[i],i});


for (int i=0; i<m;i++){
	while (q[i].size()>db[i]){
		plussz.push(q[i].top().second);
		ans+=q[i].top().first;
		q[i].pop();
		dbz[i]--;
	}

	
}
for (int i=0; i<m;i++){
	if (q[i].size()==0 ){
		if (!plussz.empty()){
			
		ak[plussz.front()]=i;
		q[i].push({plussz.front(),0});
		plussz.pop();	
	}
		else{
			while (dbz[osszgy.top().second.first]==1) osszgy.pop();
			ans+=osszgy.top().first; 
			q[i].push({0,0});
			ak[osszgy.top().second.first]=i;
			osszgy.pop();

	}
	}
}
cout<<ans<<endl;

for (int i=0; i<m;i++){
	while (q[i].size()<db[i] && !plussz.empty()){
		ak[plussz.front()]=i;
		q[i].push({plussz.front(),0});
		plussz.pop();
		
	}
}
	

for (auto i:ak) cout<<i+1<<" "; 
}
SubtaskSumTestVerdictTimeMemory
base33/50
1Accepted0/03ms1960 KiB
2Accepted0/07ms3084 KiB
3Accepted2/22ms2284 KiB
4Accepted2/22ms2288 KiB
5Accepted2/22ms2292 KiB
6Accepted2/22ms2216 KiB
7Wrong answer0/23ms2252 KiB
8Accepted2/23ms2592 KiB
9Accepted2/23ms2652 KiB
10Accepted2/23ms2872 KiB
11Accepted2/23ms3104 KiB
12Accepted2/23ms3096 KiB
13Wrong answer0/23ms3080 KiB
14Accepted3/33ms3316 KiB
15Wrong answer0/314ms5608 KiB
16Wrong answer0/332ms8884 KiB
17Accepted3/341ms9704 KiB
18Wrong answer0/374ms16376 KiB
19Accepted3/375ms15020 KiB
20Accepted3/379ms18592 KiB
21Accepted3/394ms18832 KiB
22Wrong answer0/4142ms28080 KiB