题意:
给你长度为n的数组,数组的每个元素表示你有无数张面值为的纸币,然后给你一个整数k,问在k张纸币中你不能组成的最小的钱是多少?
思路:
因为是不能组成的钱,那么+1张就是可以组成的钱,然后要使他最小。
贪心的说,如果要让组成的钱越少,那么小面额的纸币就要尽可能的多拿,那能拿到多少张呢?
假设你有10元和100元的纸币,那么你最多只能拿9张10元的,因为再多拿一张就可以变成100元的纸币:同样,如果你没有100的纸币但是你有1000的,那么你可以拿99张10元的纸币。
那么我们可以遍历一遍我们的数组,每次去遍历我们能拿的最大的纸币的数量,然后最后如果我们的纸币还有多的就一直拿最大的纸币就好了。
代码:
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
#define int long long
using namespace std;
const int N = 200010, mod=1e9 + 7;
int T, n, m, a[N];
signed main(){
cin>>T;
while(T--)
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
int ans=0;
m++;
for(int i=1;i<n;i++)
{
ll x=pow(10,a[i]),y=pow(10,a[i+1]);
int t=y/x-1;//当前纸币能拿的最大数量
if(t<=m){
ans+=t*x;
m-=t;
}
else{
ans+=m*x;
m=0;
break;
}
}
if(m) ans+=m*(ll)pow(10,a[n]);
cout<<ans<<endl;
}
return 0;
}