2
3 50(k)
-10 10 60微波炉最少按几次问题
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include<string.h>
using namespace std;
int a[10005];
int step[10005];
int n,now,tem;
void bfs()
{
memset(step,-1,sizeof step);
queue<int>q;
q.push(0);
step[0]=0;
while (!q.empty())
{
now=q.front();
q.pop();
for(int i=1; i<=n; i++)
{
tem=now+a[i];
if(tem<0) tem=0;
if(tem>3600) tem=3600;
if(step[tem]==-1||(step[tem]>step[now]+1))
{
step[tem]=step[now]+1;
q.push(tem);
}
}
}
}
int main ()
{
int k;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
bfs();
for(int i=k; i<=3600; i++)
{
if(step[i]!=-1)
{
printf("%d %d\n",step[i],i-k);
break;
}
}
}
return 0;
}