天天看点

CF1367 D. Task On The Board(构造)

​​linkkkk​​

题意:

给出字符串,给出个数

要求从选个不重复的位置,使得对于每个,满足如果,那么

思路:

代码:

// Problem: D. Task On The Board
// Contest: Codeforces - Codeforces Round #650 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1367/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
#define read read()
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define dep(i, a, b) for(int i=(a);i>=(b);--i)
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=4e5+7,maxm=1e6+7,mod=1e9+7;
int a[30],b[55];
char ans[55];
vector<int>v;
int main(){
  int _=read;
  while(_--){
    string s;cin>>s;
    int m=read;
    rep(i,1,m) b[i]=read,ans[i]='*';
    memset(a,0,sizeof a);
    for(int i=0;s[i];i++) a[s[i]-'a']++;
    int pos=25;
    while(1){
      v.clear();
      int zero=0,cnt=0;
      rep(i,1,m){
        if(ans[i]!='*'){
            cnt++;continue;
        }
        if(!b[i]) v.push_back(i),zero++;
      }
      if(cnt==m) break;
      while(a[pos]<zero) pos--;
      a[pos]-=zero;
    //  cout<<zero<<" "<<pos<<endl;
      rep(i,1,m){
          if(ans[i]!='*') continue;
        if(!b[i]) ans[i]=char(pos+'a');
        else{
          for(auto tt:v) b[i]=b[i]-abs(i-tt);
        }
      }
      pos--;
      //cout<<pos<<endl;
    }
    
    rep(i,1,m) cout<<ans[i];
    puts("");
  }
  return 0;
}