41542023-03-15 15:54:51horvathabelÓvodacpp17Wrong answer 13/5090ms17240 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()){
		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
base13/50
1Wrong answer0/03ms1808 KiB
2Runtime error0/06ms2592 KiB
3Partially correct1/23ms2320 KiB
4Partially correct1/23ms2532 KiB
5Partially correct1/23ms2740 KiB
6Accepted2/23ms3052 KiB
7Wrong answer0/23ms3160 KiB
8Partially correct1/23ms3208 KiB
9Accepted2/23ms3304 KiB
10Partially correct1/23ms3420 KiB
11Partially correct1/23ms3536 KiB
12Partially correct1/23ms3744 KiB
13Runtime error0/23ms3972 KiB
14Partially correct1/33ms4000 KiB
15Runtime error0/312ms5244 KiB
16Runtime error0/325ms7412 KiB
17Runtime error0/330ms6628 KiB
18Runtime error0/352ms11084 KiB
19Runtime error0/354ms8504 KiB
20Partially correct1/370ms8464 KiB
21Runtime error0/371ms10196 KiB
22Runtime error0/490ms17240 KiB