比赛 |
2025暑假集训第一场 |
评测结果 |
AAWWWWWWWWWWEEEEEEEE |
题目名称 |
挑战 NPH |
最终得分 |
10 |
用户昵称 |
二乾五 |
运行时间 |
1.434 s |
代码语言 |
C++ |
内存使用 |
4.40 MiB |
提交时间 |
2025-06-25 11:00:44 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define cl(a) memset(a,0,sizeof a)
#define copy(a,b) copy(begin(a),end(a),begin(b))
#define ld long double
#define dot(x) fixed<<setprecision(x)
#define foru(a,b,c) for(ll a=b;a<=c;a++)
ll t,n,k,w[1050],cnt,sum,a[100050];
bool ok(ll n,ll w[]){
for(ll i=1;i<=n;i++){
if(w[i]!=1){
return 0;
}
}
return 1;
}
ll bfs(){
queue<ll>q;
q.push(0);
cnt=0;
// cerr<<"#"<<t<<" "<<endl;
while(!q.empty()){
ll x=q.front();
// cerr<<x<<" ";
q.pop();
for(ll i=1;i<=n;i++){
if(cnt<=100048){
a[++cnt]=x+w[i];
q.push(x+w[i]);
// cerr<<x<<" "<<w[i]<<" ";
}else{
break;
}
}
}
// cerr<<endl;
sort(a+1,a+cnt+1);
// for(ll i=1;i<=k;i++){
// cerr<<a[i]<<" ";
// }
// cerr<<endl;
return a[k];
}//lty 1 11 2 12 111
void real_mian(){
cin>>n>>k;
for(ll i=1;i<=n;i++){
cin>>w[i];
}
if(n==1){
cout<<w[1]*k<<endl;
}else if(ok(n,w)){
if(k<=n){
cout<<k<<endl;
}else{
cout<<ceil(k*1.0/n)<<endl;
}
}else if(k==1){
sort(w+1,w+n+1);
cout<<w[1]<<endl;
}else{
cout<<bfs()<<endl;
}
}
int main(){
freopen("NPH.in","r",stdin);
freopen("NPH.out","w",stdout);
cin>>t;
while(t--){
real_mian();
}
return 0;
}
/*
1
1 1 2 2 2
1 1 2 2 2 2 3 3 3 3
*/