44302023-03-27 20:08:30horvathabelÓvodacpp17Wrong answer 33/50145ms28572 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();	
		dbz[i]++; 
	}
		
	}
}
for (int i=0; i<m;i++){
	if (q[i].size()==0){
			while (dbz[osszgy.top().second.first]==1) osszgy.pop();
			ans+=osszgy.top().first; 
			q[i].push({0,0});
			ak[osszgy.top().second.second]=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/03ms1808 KiB
2Accepted0/07ms2932 KiB
3Accepted2/23ms2300 KiB
4Accepted2/23ms2272 KiB
5Accepted2/23ms2460 KiB
6Accepted2/23ms2676 KiB
7Wrong answer0/23ms2892 KiB
8Accepted2/22ms2972 KiB
9Accepted2/23ms3096 KiB
10Accepted2/23ms3188 KiB
11Accepted2/23ms3312 KiB
12Accepted2/23ms3532 KiB
13Wrong answer0/23ms3988 KiB
14Accepted3/33ms3992 KiB
15Wrong answer0/314ms6008 KiB
16Wrong answer0/332ms9596 KiB
17Accepted3/339ms10360 KiB
18Wrong answer0/372ms16828 KiB
19Accepted3/372ms15720 KiB
20Accepted3/381ms19112 KiB
21Accepted3/393ms19364 KiB
22Wrong answer0/4145ms28572 KiB