41362023-03-15 13:21:33horvathabelÓvodacpp17Wrong answer 28/50105ms16756 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++){
	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
base28/50
1Accepted0/03ms1940 KiB
2Wrong answer0/07ms2432 KiB
3Accepted2/23ms2220 KiB
4Partially correct1/23ms2396 KiB
5Accepted2/23ms2608 KiB
6Accepted2/23ms2852 KiB
7Wrong answer0/23ms3084 KiB
8Partially correct1/23ms3264 KiB
9Accepted2/23ms3212 KiB
10Accepted2/23ms3272 KiB
11Accepted2/23ms3580 KiB
12Partially correct1/23ms3544 KiB
13Wrong answer0/23ms3784 KiB
14Accepted3/33ms3784 KiB
15Wrong answer0/313ms4636 KiB
16Wrong answer0/328ms6936 KiB
17Accepted3/337ms6044 KiB
18Wrong answer0/361ms10312 KiB
19Accepted3/365ms7832 KiB
20Accepted3/371ms8840 KiB
21Partially correct1/385ms9544 KiB
22Wrong answer0/4105ms16756 KiB