41562023-03-15 15:56:44horvathabelÓvodacpp17Wrong answer 33/5092ms17176 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){
		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/03ms1812 KiB
2Accepted0/06ms2476 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2512 KiB
5Accepted2/23ms2764 KiB
6Accepted2/23ms2796 KiB
7Wrong answer0/23ms2844 KiB
8Accepted2/23ms2840 KiB
9Accepted2/23ms2852 KiB
10Accepted2/23ms3092 KiB
11Accepted2/23ms3308 KiB
12Accepted2/23ms3524 KiB
13Runtime error0/24ms3876 KiB
14Accepted3/33ms3824 KiB
15Runtime error0/312ms4988 KiB
16Runtime error0/325ms7364 KiB
17Accepted3/337ms5812 KiB
18Runtime error0/352ms10672 KiB
19Accepted3/365ms7924 KiB
20Accepted3/371ms9000 KiB
21Accepted3/386ms9880 KiB
22Runtime error0/492ms17176 KiB