41572023-03-15 16:00:56horvathabelÓvodacpp17Wrong answer 33/50108ms17104 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
int n,m;
cin>>n>>m;
vector<int> db; 
for (int i=0; i<m;i++){
	int z;
	cin>>z;
	db.push_back(z);
}
vector<int> ak,sir;
for (int i=0; i<n;i++){
	int x;
	cin>>x;
	x--;
	ak.push_back(x);
}
for (int i=0; i<n;i++){
	int x;
	cin>>x;
	sir.push_back(x);
}
vector<priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>> q(m);
for (int i=0; i<n;i++){
	q[ak[i]].push({sir[i],i});
}
int ans=0;
queue<int> plussz;
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();
	}

	
}

cout<<ans<<endl; 
for (int i=0; i<m;i++){
	if (q[i].size()==0 && !plussz.empty()){
		ak[plussz.front()]=i;
		q[i].push({plussz.front(),0});
		plussz.pop();	
	}
}
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/06ms2480 KiB
3Accepted2/23ms2212 KiB
4Accepted2/23ms2368 KiB
5Accepted2/23ms2564 KiB
6Accepted2/23ms2804 KiB
7Wrong answer0/23ms3016 KiB
8Accepted2/23ms3232 KiB
9Accepted2/23ms3456 KiB
10Accepted2/23ms3632 KiB
11Accepted2/23ms3836 KiB
12Accepted2/23ms3956 KiB
13Wrong answer0/23ms4128 KiB
14Accepted3/33ms3980 KiB
15Wrong answer0/314ms5100 KiB
16Wrong answer0/328ms7848 KiB
17Accepted3/337ms6472 KiB
18Wrong answer0/361ms10876 KiB
19Accepted3/365ms8388 KiB
20Accepted3/371ms9456 KiB
21Accepted3/386ms10148 KiB
22Wrong answer0/4108ms17104 KiB