41352023-03-15 13:16:30horvathabelÓvodacpp17Wrong answer 21/50103ms17380 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()<db[i] && !plussz.empty()){
		ak[plussz.front()]=i;
		plussz.pop();
	}
}
for (auto i:ak) cout<<i+1<<" "; 
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1808 KiB
2Wrong answer0/06ms2488 KiB
3Partially correct1/23ms2384 KiB
4Partially correct1/23ms2580 KiB
5Partially correct1/23ms2676 KiB
6Accepted2/23ms2852 KiB
7Wrong answer0/23ms3244 KiB
8Partially correct1/23ms3252 KiB
9Accepted2/23ms3248 KiB
10Accepted2/23ms3480 KiB
11Partially correct1/23ms3728 KiB
12Partially correct1/23ms3756 KiB
13Wrong answer0/23ms4168 KiB
14Partially correct1/33ms4340 KiB
15Wrong answer0/313ms5368 KiB
16Wrong answer0/328ms7564 KiB
17Accepted3/335ms6552 KiB
18Wrong answer0/359ms10900 KiB
19Accepted3/364ms8416 KiB
20Partially correct1/370ms8900 KiB
21Partially correct1/383ms10292 KiB
22Wrong answer0/4103ms17380 KiB