41552023-03-15 15:55:32horvathabelÓvodacpp17Wrong answer 18/5090ms17296 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.push(q[i].top().second);
		ans+=q[i].top().first;
		q[i].pop();
	}

	
}
for (auto i:ak) cout<<i+1<<" "; 
}
SubtaskSumTestVerdictTimeMemory
base18/50
1Accepted0/03ms1812 KiB
2Wrong answer0/06ms2480 KiB
3Partially correct1/23ms2268 KiB
4Accepted2/23ms2352 KiB
5Partially correct1/23ms2432 KiB
6Accepted2/23ms2636 KiB
7Wrong answer0/23ms2852 KiB
8Partially correct1/23ms3092 KiB
9Accepted2/23ms3308 KiB
10Accepted2/23ms3540 KiB
11Partially correct1/23ms3728 KiB
12Partially correct1/23ms3764 KiB
13Runtime error0/23ms4136 KiB
14Partially correct1/33ms4244 KiB
15Runtime error0/312ms5380 KiB
16Runtime error0/325ms7896 KiB
17Partially correct1/335ms6576 KiB
18Runtime error0/352ms11276 KiB
19Partially correct1/364ms8396 KiB
20Partially correct1/370ms8484 KiB
21Partially correct1/385ms9840 KiB
22Runtime error0/490ms17296 KiB