R(0)、R(1)、R(2)…R(23)表示第x个时刻需要R(x)个出纳员,有n个出纳员申请工作,第i个出纳员从t_i时刻开始工作8小时,问至少需要多少出纳员?
个人。
设,可得:
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#define E 2000010
#define eps 1e-10
#define ll long long
using namespace std;
inline ll read(){
ll res=0,f=1;char ch=getchar();
while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
return res*f;
}
inline void write(ll x){
if(x<0) putchar('-'),x=-x;
if(x<10) putchar(x+'0');
else{
write(x/10);
putchar(x%10+'0');
}
}
//queue<ll> q;
//set<ll> s;
//priority_queue<ll> q1;
//priority_queue<ll,vector<ll>,greater<ll> > q2;
//list<ll> l;
//stack<ll> s;
ll n,m;
ll fir[E],nxt[E],son[E],tot;
int w[E];
void add(ll x,ll y,ll z){++tot;nxt[tot]=fir[x];son[tot]=y;fir[x]=tot;w[tot]=z;}
int dis[E],flag;
ll vis[E];
queue<int> q;
int tt[E];
ll spfa(ll s){
memset(dis,63,sizeof(dis));
memset(tt,0,sizeof(tt));
memset(vis,0,sizeof(vis));
dis[24]=0;
vis[24]=1;
q.push(24);
while(!q.empty()){
int u=q.front();q.pop();
for(ll i=fir[u];i;i=nxt[i]){
ll to=son[i];
if(dis[u]+w[i]<dis[to]){
dis[to]=dis[u]+w[i];
tt[to]++;
if(tt[to]>n+1){
return 0;
}
if(vis[to]==0){
vis[to]=1;
q.push(to);
}
}
}
vis[u]=0;
}
return dis[0]==-s;
}
ll T,r[E],Min,Max,s[E],num[E];
void work(int x){
memset(fir,0,sizeof(fir));tot=0;
for(register int i=1;i<=24;i++) add(i,i-1,0),add(i-1,i,num[i]);
for(register int i=8;i<=24;i++) add(i,i-8,-r[i]);
for(register int j=1;j<=7;j++) add(j,j+16,x-r[j]);
add(24,0,-x);
}
int main(){
T=read();
while(T--){
for(int i=1;i<=24;i++){
r[i]=read();num[i]=0;
}
n=read();
for(int i=1;i<=n;i++){
int t=read();t++;
num[t]++;
}
int l=0,r=n,ans=2e9;
while(l<=r){
int mid=(l+r)/2;
work(mid);
if(spfa(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
if(ans==2e9) puts("No Solution");
else write(ans),putchar('\n');
}
return 0;
}