2312021-03-05 10:49:59mraronÓvodacpp14Accepted 50/5050ms13524 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


struct ch {
	int xx,yy,ind;
	bool operator<(const ch& masik) const {return mp(xx,yy)<mp(masik.xx,masik.yy);}
};

int main() {
	IO;
	int n,k;
	cin>>n>>k;
	vector<int> lim(k), volt(k);
	for(int i=0;i<k;++i) {
		cin>>lim[i];
	}
	vector<ch> chs(n);
	for(int i=0;i<n;++i) cin>>chs[i].yy, chs[i].yy--;
	for(int i=0;i<n;++i) cin>>chs[i].xx, chs[i].ind=i;;
	
	sort(all(chs));
	reverse(all(chs));
	
	int res=0;
	vector<int> ans(n), lst, lst_act;
	int rem=n;
	for(auto i:chs) {
		if(lim[i.yy] && (rem>k || (rem==k && !volt[i.yy]))) {
			lim[i.yy]--;
			if(!volt[i.yy]) k--;
			volt[i.yy]=1;
			ans[i.ind]=i.yy;
			rem--;
		}else {
			res+=i.xx;
			lst.pb(i.ind);
		}		
	}
	
	for(int i=0;i<sz(volt);++i) if(!volt[i]) lst_act.pb(i);
	
	int ind=0;
	for(auto i:lst) {
		if(ind>=sz(lst_act))
			for(int j=0;j<sz(lim);++j) 
				if(lim[j]>0) lst_act.pb(j);
		
		ans[i]=lst_act[ind++];
		if(--lim[ans[i]]) lst_act.pb(ans[i]);
	}
	
	cout<<res<<"\n";
	for(auto i:ans) cout<<i+1<<" ";
	cout<<"\n";

	
	return 0;
	
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1756 KiB
2Accepted0/03ms2076 KiB
3Accepted2/21ms1904 KiB
4Accepted2/21ms1892 KiB
5Accepted2/21ms1904 KiB
6Accepted2/21ms1924 KiB
7Accepted2/21ms1912 KiB
8Accepted2/21ms1932 KiB
9Accepted2/21ms1936 KiB
10Accepted2/21ms1924 KiB
11Accepted2/21ms1924 KiB
12Accepted2/21ms1928 KiB
13Accepted2/21ms2004 KiB
14Accepted3/31ms2000 KiB
15Accepted3/36ms2568 KiB
16Accepted3/313ms3884 KiB
17Accepted3/319ms4240 KiB
18Accepted3/329ms6704 KiB
19Accepted3/341ms7304 KiB
20Accepted3/341ms8920 KiB
21Accepted3/343ms10128 KiB
22Accepted4/450ms13524 KiB