exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 6415560b383cb78f61636e376becbebb | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException
{
FastScanner f= new FastScanner();
int ttt=1;
ttt=f.nextInt();
PrintWriter out=new PrintWriter(System.out);
outer: for(int tt=0;tt<ttt;tt++) {
int n=f.nextInt();
int k=f.nextInt()+1;
int[] l=f.readArray(n);
int[] ans=new int[n];
for(int i=0;i<n-1;i++) {
int val=(int)((Math.pow(10, l[i+1])-Math.pow(10,l[i]))/Math.pow(10, l[i]));
// System.out.println(val);
if(val<=k) {
k-=val;
ans[i]=val;
}
else {
ans[i]=k;
k=0;
}
}
// System.out.println(k);
if(k>0) {
ans[n-1]+=k;
}
// System.out.println(Arrays.toString(ans));
String num="";
for(int i=0;i<n;i++) {
if(ans[i]==0) continue;
while(num.length()<l[i]) {
num="0"+num;
}
num=Integer.toString(ans[i])+num;
// System.out.println(num);
}
System.out.println(num);
}
out.close();
}
static void sort(int[] p) {
ArrayList<Integer> q = new ArrayList<>();
for (int i: p) q.add( i);
Collections.sort(q);
for (int i = 0; i < p.length; i++) p[i] = q.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long[] readLongArray(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 21d90264ce0f9c4b2cd06715be131b7b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
FastScanner fs=new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int T = fs.nextInt();
for (int tt=0; tt<T; tt++) {
int n = fs.nextInt();
int k = fs.nextInt();
int[] arr = fs.readArray(n);
ruffleSort(arr);
long sum = 0;
int notes = 0;
int ii=0;
while (notes<=k && ii<n-1) {
if (notes+(long)Math.pow(10,(arr[ii+1]-arr[ii]))-1>k) {
sum+=(k+1-notes)*(long)Math.pow(10,arr[ii]);
notes=k+1;
break;
}
notes+=(long)Math.pow(10,(arr[ii+1]-arr[ii]))-1;
sum+=((long)(Math.pow(10,arr[ii+1]-arr[ii])-1)*Math.pow(10,arr[ii]));
ii++;
// System.out.println(notes+","+ sum+","+ ii);
}
if (notes<=k) {
sum+=(k+1-notes)*(long)Math.pow(10,arr[ii]);
}
out.println(sum);
}
out.close();
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | aab6eecb79d1cdbf579162c4652f9a55 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | //created by Whiplash99
import java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,N;
int T=Integer.parseInt(br.readLine().trim());
StringBuilder sb=new StringBuilder();
long[] pow=new long[19]; pow[0]=1;
for(i=1;i<pow.length;i++) pow[i]=pow[i-1]*10;
long[] freq=new long[11];
while (T-->0)
{
String[] s=br.readLine().trim().split(" ");
N=Integer.parseInt(s[0]);
long K=Long.parseLong(s[1]);
s=br.readLine().trim().split(" ");
int[] a=new int[N+1]; a[N]=10;
for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);
long count=0;
for(i=1;i<=N;i++)
{
long lim=pow[a[i]]-1;
if(i==N) lim=pow[18]-1;
Arrays.fill(freq,0);
count=0;
for(int j=i-1;j>=0;j--)
{
long tmp=lim/pow[a[j]];
lim%=pow[a[j]];
count+=tmp;
freq[j]=tmp;
}
if(count>K) break;
}
long extra=(count-(K+1));
for(int j=i-1;j>=0;j--)
{
long tmp=Math.min(extra,freq[j]);
freq[j]-=tmp;
extra-=tmp;
}
long ans=0;
for(i=0;i<N;i++) ans+=pow[a[i]]*freq[i];
sb.append(ans).append("\n");
}
System.out.println(sb);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d97af2951564993e69f1cff8280d07fb | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Banknotes {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tests = sc.nextInt();
sc.nextLine();
for(int i = 0;i<tests;i++) {
String firstLine = sc.nextLine();
String[] banknotes = sc.nextLine().split(" ");
int k = Integer.parseInt(firstLine.split(" ")[1]);
int[] banks = Arrays.stream(banknotes).mapToInt(Integer::parseInt).toArray();
solution(k, banks);
}
}
public static void solution(int k, int[] banknotes) {
k++;
int[] poweredNumbs = Arrays.stream(banknotes).map(num -> (int) Math.pow(10, num)).toArray();
long result = 0;
int remaining = k;
for(int i = 0;i<banknotes.length;i++) {
int maxPotential = i + 1 < banknotes.length ? poweredNumbs[i + 1] / poweredNumbs[i] - 1 : remaining;
if(maxPotential > remaining || banknotes.length - 1 == i) {
result += (long) poweredNumbs[i] * remaining;
System.out.println(result);
return;
} else {
result += poweredNumbs[i] * maxPotential;
remaining -= maxPotential;
}
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 1d80f15ed3189a910da5a725da8173d5 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Stream;
public class CasimirString {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
int cases = Integer.parseInt(reader.readLine());
long[] tenPower = new long[10];
long pow = 1;
for(int i=0;i<10;i++) {
tenPower[i] = pow;
pow *= 10;
}
while(cases-- > 0) {
String[] firstLine = reader.readLine().split(" ");
long n = Long.parseLong(firstLine[0]);
long k = Long.parseLong(firstLine[1]);
Integer[] deno = convertToIntArray(reader.readLine().split(" "));
long ans = 0;
k++;
int i = 0;
while(i<deno.length-1) {
if(k==0) {
break;
}
long count = (tenPower[deno[i+1]] - tenPower[deno[i]])/tenPower[deno[i]];
if(count > k) {
ans += k*tenPower[deno[i]];
k-=k;
}else {
ans += count*tenPower[deno[i]];
k-=count;
}
i++;
}
if(k>0) {
ans += k*tenPower[deno[i]];
k-=k;
}
printNumber(ans);
}
out.flush();
}
public static List<Integer> func(Integer[] arr, int index) {
List<Integer> list = new ArrayList<>();
for(int i=index;i<arr.length;i+=2) {
if((arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0)) {
list.add(-1*arr[i+1]);
list.add(arr[i]);
}else {
list.add(Math.abs(arr[i+1]));
list.add(Math.abs(arr[i]));
}
}
return list;
}
public static Integer[] convertToIntArray(String[] str) {
Integer[] arr = new Integer[str.length];
for(int i=0;i<str.length;i++) {
arr[i] = Integer.parseInt(str[i]);
}
return arr;
}
public static Long[] convertToLongArray(String[] str) {
Long[] arr = new Long[str.length];
for(int i=0;i<str.length;i++) {
arr[i] = Long.parseLong(str[i]);
}
return arr;
}
public static void printYes() throws IOException {
out.append("YES" + "\n");
}
public static void printNo() throws IOException {
out.append("NO" + "\n");
}
public static void printNumber(long num) throws IOException {
out.append(num + "\n");
}
public static long hcf(long a, long b) {
if(b==0) return a;
return hcf(b, a%b);
}
public static int findSet(int[] parent, int[] rank, int v) {
if(v==parent[v]) {
return v;
}
parent[v] = findSet(parent, rank, parent[v]);
return parent[v];
}
public static void unionSet(int[] parent, int[] rank, int a, int b) {
a = findSet(parent, rank, a);
b = findSet(parent, rank, b);
if(a == b) {
return;
}
if(rank[a] < rank[b]) {
int temp = a;
a = b;
b = temp;
}
parent[b] = a;
if(rank[a] == rank[b]) {
rank[a]++;
}
}
public static void makeSet(int[] parent, int[] rank, int v) {
parent[v] = v;
rank[v] = 0;
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | fed6ea9bbb4cb2308e4d53ac147eda99 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
public class M {
static Scanner scanner=new Scanner(System.in);
static BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int t=scanner.nextInt();
l:while(t-->0) {
int n=scanner.nextInt();
int k=scanner.nextInt()+1;
int a[]=new int [n+1];
for(int i=0;i<n;i++) {
a[i]=scanner.nextInt();
}
a[n]=11;
long ans=0;
for(int i=0;k>0;i++) {
//
for(int j=0;j<=n;j++) {
if(j==n) {
ans+=(long)Math.pow(10, a[j-1])*k;
System.out.println(ans);
continue l;
}else if(a[j]>i){
long w=9*(long)Math.pow(10, i-a[j-1]);
//System.out.println(w+"pppppp"+(i-a[j-1]));
if(w>=k) {
ans+=(long)Math.pow(10, a[j-1])*k;
System.out.println(ans);
continue l;
}else {
ans+=(long)Math.pow(10, a[j-1])*w;
k-=w;
}
break;
}
}
}
System.out.println(ans);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 53a2867c7480d967b54b8ba3d02a7322 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /*
stream Butter!
eggyHide eggyVengeance
I need U
xiao rerun when
*/
import static java.lang.Math.*;
import java.util.*;
import java.io.*;
import java.math.*;
public class x1606C
{
static long[] pow10;
public static void main(String hi[]) throws Exception
{
pow10 = new long[19];
pow10[0] = 1L;
for(int i=1; i < 19; i++)
pow10[i] = pow10[i-1]*10;
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int T = Integer.parseInt(st.nextToken());
StringBuilder sb = new StringBuilder();
while(T-->0)
{
st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(st.nextToken());
int[] arr = readArr(N, infile, st);
long current = 0L;
outer:for(int i=18; i >= 0; i--)
for(int d=0; d < 10; d++)
{
long val = current+d*pow10[i];
for(int a=i-1; a >= 0; a--)
val += 9*pow10[a];
if(calc(val, arr) > K)
{
current += d*pow10[i];
continue outer;
}
}
sb.append(current+"\n");
}
System.out.print(sb);
}
public static long calc(long X, int[] arr)
{
long res = 0L;
for(int i=arr.length-1; i >= 0; i--)
{
long val = pow10[arr[i]];
res += X/val;
X %= val;
}
return res;
}
public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception
{
int[] arr = new int[N];
st = new StringTokenizer(infile.readLine());
for(int i=0; i < N; i++)
arr[i] = Integer.parseInt(st.nextToken());
return arr;
}
}
/*
f(s) can be found with easy greedy
is 99...99 the "highest cost" with d digits? (yes)
at most 18 digits
*/ | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | b08a5dc217e004aceefed123b5179f1a | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | // Working program with FastReader
import java.io.*;
import java.util.*;
public class gg
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static final int MAXN = 100001;
// stores smallest prime factor for every number
static int spf[] = new int[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
static void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i=4; i<MAXN; i+=2)
spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
// checking if i is prime
if (spf[i] == i)
{
// marking SPF for all numbers divisible by i
for (int j=i*i; j<MAXN; j+=i)
// marking spf[j] if it is not
// previously marked
if (spf[j]==j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
static int getFactorization(int x)
{
int c=0;
while (x != 1)
{
c++;
x = x / spf[x];
}
return c;
}
/*
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(int a[], int x) {// x is the key or target value
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
*/
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// method to return LCM of two numbers
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
public static int[] swap(int a[], int left, int right)
{
int temp = a[left];
a[left] = a[right];
a[right] = temp;
return a;
}
public static int[] reverse(int a[], int left, int right)
{
// Reverse the sub-array
while (left < right) {
int temp = a[left];
a[left++] = a[right];
a[right--] = temp;
}
return a;
}
public static int[] findNextPermutation(int a[])
{
int last = a.length - 2;
// find the longest non-increasing suffix
// and find the pivot
while (last >= 0) {
if (a[last] < a[last + 1]) {
break;
}
last--;
}
// If there is no increasing pair
// there is no higher order permutation
if (last < 0)
return a;
int nextGreater = a.length - 1;
// Find the rightmost successor to the pivot
for (int i = a.length - 1; i > last; i--) {
if (a[i] > a[last]) {
nextGreater = i;
break;
}
}
// Swap the successor and the pivot
a = swap(a, nextGreater, last);
// Reverse the suffix
a = reverse(a, last + 1, a.length - 1);
// Return true as the next_permutation is done
return a;
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static double pow(double p,double tt)
{
double ii,q,r;
q=1;
r=p;
while(tt>1)
{
for(ii=1;2*ii<=tt;ii*=2)
p*=p;
tt-=ii;
q*=p;
p=r;
}
if(tt==1)
q*=r;
return q;
}
static long pow(long p,long tt,long mod)
{
long ii,q,r;
q=1l;
r=p;
while(tt>1)
{
for(ii=1l;2*ii<=tt;ii*=2l)
p=((p%mod)*(p%mod))%mod;
tt-=ii;
q=((q%mod)*(p%mod))%mod;
p=r;
}
if(tt==1)
q=((q%mod)*(r%mod))%mod;
return q;
}
static int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
public static long primeFactors(long n)
{
long c=0l;
long max=0l;
long z=0l;
//ArrayList <Integer> ll=new ArrayList<>();
// Print the number of 2s that divide n
while (n%2==0)
{
c++;
n /= 2l;
//ll.add(2);
}
if(c>max)
{
max=c;
z=2;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i+= 2)
{
// While i divides n, print i and divide n
c=0;
while (n%i == 0)
{
c++;
n /= i;
//ll.add(i);
}
if(c>max)
{
max=c;
z=i;
}
}
c=0;
// This condition is to handle the case whien
// n is a prime number greater than 2
if (n > 2)
{
c++;
//ll.add((int)n);
}
if(c>max)
{
max=c;
z=n;
}
return z;
}
static void PrimeList(){
int i,j;
int sieve[]=new int[100001];
for(i=2;i*i<=100000;i++)
{
if(sieve[i]==0)
{
for(j=i*i;j<=100000;j+=i)
sieve[j]=1;
}
}
ArrayList<Integer> primes=new ArrayList<>();
for(i=2;i<=100000;i++)
{
if(sieve[i]==0)
primes.add(i);
}
}
static int comp(int a[],int b[],int n)
{
int z=0;
for(int i=0;i<n;i++)
{
if(a[i]!=b[i])
{
z=1;
break;
}
}
if(z==0)
return 1;
else
return 0;
}
static boolean isPowerOfTwo(int x)
{
return x!=0 && ((x&(x-1))==0);
}
static long divide_ceil(long a,long b)
{
return (a%b==0)?(a/b):(a/b+1l);
}
public static void main(String[] args)
{
//try
//{
FastReader d=new FastReader();
PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t,i,j,k,l,r,n;
int mod = (int) 1e9 + 7;
int Inf=Integer.MAX_VALUE;
int negInf=Integer.MIN_VALUE;
t=d.nextInt();
//t=1;
String s;
//char ch1,ch2,ch3,ch4;
long ans,c,z;
while(t-->0)
{
z=c=0l;
ans=0l;
n=d.nextInt();
k=d.nextInt()+1;
int a[]=new int[n];
for(i=0;i<n;i++)
a[i]=(int)Math.pow(10,d.nextInt());
i=0;
while(i<n-1)
{
long x=(a[i+1]-a[i])/a[i];
if(k>=x)
{
ans+=(long)(x*a[i]);
k-=x;
}
else
{
ans+=(long)(k*a[i]);
k-=k;
break;
}
i++;
}
if(k>0)
ans+=((long)k*(long)a[n-1]);
pr.println(ans);
}
/*
}catch(Exception e) {
System.out.println(0);
}*/
pr.flush();
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | a315ea03340842e70237bd8b8d3647aa | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Banknotes {
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
for (int i = 1; i <= t; i++) {
int n = in.nextInt();
long k = in.nextLong();
int[] a = new int[n];
for (int j = 0; j < n; j++) {
a[j] = in.nextInt();
}
long[] max = new long[n];
for (int j = 0; j < n - 1; j++) {
max[j] = (long) Math.pow(10, a[j + 1] - a[j]) - 1;
}
max[n - 1] = k;
long sum = 0;
long count = 0;
long left = (k + 1) - count;
for (int j = 0; j < n - 1; j++) {
if (max[j] >= left) {
sum += left * (long) Math.pow(10, a[j]);
left = 0;
break;
}
else {
sum += max[j] * (long) Math.pow(10, a[j]);
left -= max[j];
}
}
sum += left * (long) Math.pow(10, a[n - 1]);
out.println(sum);
}
out.close();
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// noop
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | be1ed3e6297188e55a1498488646d239 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CBanknotes solver = new CBanknotes();
solver.solve(1, in, out);
out.close();
}
static class CBanknotes {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int k = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
int num = in.nextInt();
arr[i] = (int) Math.pow(10, num);
}
long res = 0;
k++;
for (int i = 0; i < n; i++) {
if (i == n - 1) {
res += (long) k * arr[i];
break;
}
int cur = arr[i + 1] / arr[i] - 1;
if (cur < k) {
k = k - cur;
res += (long) cur * arr[i];
} else {
res += (long) k * arr[i];
break;
}
}
out.println(res);
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 8aee2c79362e4419f84e89ea84097291 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class Banknotes {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int tc = Integer.parseInt(scanner.next());
while(tc-- > 0) {
int n = Integer.parseInt(scanner.next());
int k = Integer.parseInt(scanner.next()) + 1;
int[] a = new int[n];
for(int i = 0 ; i < n ; i++) {
a[i] = Integer.parseInt(scanner.next());
}
long count = 0;
for(int j = 0 ; j < n-1 ; j++) {
if(k>0) {
long now = (long)(Math.pow(10, a[j+1] - a[j]) - 1);
long ans = Math.min(now, k);
count = (long)Math.pow(10, a[j])*ans + count;
k -= ans;
}
}
if(k>0) {
count += (long)Math.pow(10, a[n-1])*k;
}
System.out.println(count);
}
scanner.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 6d4238c6c224bc0d32d8828710880be4 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class pre160 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]){
FastReader obj = new FastReader();
int tc = obj.nextInt();
while(tc--!=0){
int n = obj.nextInt(),k = obj.nextInt()+1,arr[] = new int[n];
for(int i=0;i<n;i++) arr[i] = obj.nextInt();
long ans = 0;
for(int i=0;i<n && k>0;i++){
if(i==n-1){
ans+=k*(long)Math.pow(10,arr[i]);
// System.out.println((long)Math.pow(10,arr[i])+" "+k+" ");
k = 0;
}
else{
int l = Math.min(k,(int)Math.pow(10,(arr[i+1]-arr[i]))-1);
ans += l * (long)Math.pow(10,arr[i]);
k-=l;
}
}
System.out.println(ans);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 66854ae3b657c2367d77556805bb94cf | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /*
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀⢠⠞⠉⠙⠲⡀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀⡏⠀⠀Y⠀⠀⢷
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀⢸⠀⠀A⠀⠀ ⡇
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀⣸⠀⠀S⠀ ⡇
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀⢹⠀⠀H⠀⠀ ⡇
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀⡇⠀⠀⠀⠀⡼
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀⠘⠤⣄⣠⠞⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿………⣀⣰⣏⣘⣆⣀⠀⠀
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter; // System.out is a PrintStream
import java.util.InputMismatchException;
public class C1606 {
private static int MOD = (int)1e9 + 7, mod = 99_82_44_353;
private static double PI = 3.14159265358979323846;
public static void main(String[] args) throws IOException {
FasterScanner scn = new FasterScanner();
PrintWriter out = new PrintWriter(System.out);
loop:
for (int tc = scn.nextInt(); tc > 0; tc--) {
long N = scn.nextInt(), K = 1 + scn.nextInt();
long[] arr = new long[(int)N];
long val = 0;
for (int i = 0; i < N; i++) {
arr[i] = pow(10L, scn.nextLong());
}
for (int i = 0; i < N; i++) {
long mn = K;
if (i + 1 < N) mn = Math.min(mn, (arr[i + 1] / arr[i]) - 1);
val += arr[i] * mn;
K -= mn;
}
out.println(val);
}
out.close();
}
/* ------------------- Sorting ------------------- */
private static void ruffleSort(int[] arr) {
// int N = arr.length;
// Random rand = new Random();
// for (int i = 0; i < N; i++) {
// int oi = rand.nextInt(N), temp = arr[i];
// arr[i] = arr[oi];
// arr[oi] = temp;
// }
// Arrays.sort(arr);
}
/* ------------------- Sorting ------------------- */
private static boolean isPalindrome(String str) {
for (int i = 0, j = str.length() - 1; i < j; i++, j--) {
if (str.charAt(i) != str.charAt(j)) {
return false;
}
}
return true;
}
private static boolean isPalindrome(char[] str) {
for (int i = 0, j = str.length - 1; i < j; i++, j--) {
if (str[i] != str[j]) {
return false;
}
}
return true;
}
/* ------------------- Pair class ------------------- */
private static class Pair implements Comparable<Pair> {
int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return this.x == o.x ? this.y - o.y : this.x - o.x;
}
}
/* ------------------- HCF and LCM ------------------- */
private static int gcd(int num1, int num2) {
int temp = 0;
while (num2 != 0) {
temp = num1;
num1 = num2;
num2 = temp % num2;
}
return num1;
}
private static int lcm(int num1, int num2) {
return (int)((1L * num1 * num2) / gcd(num1, num2));
}
/* ------------------- primes and prime factorization ------------------- */
private static boolean[] seive(int N) {
// true means not prime, false means is a prime number :)
boolean[] notPrimes = new boolean[N + 1];
notPrimes[0] = notPrimes[1] = true;
for (int i = 2; i * i <= N; i++) {
if (notPrimes[i]) continue;
for (int j = i * i; j <= N; j += i) {
notPrimes[j] = true;
}
}
return notPrimes;
}
/*
private static TreeMap<Integer, Integer> primeFactors(long N) {
TreeMap<Integer, Integer> primeFact = new TreeMap<>();
for (int i = 2; i <= Math.sqrt(N); i++) {
int count = 0;
while (N % i == 0) {
N /= i;
count++;
}
if (count != 0) {
primeFact.put(i, count);
}
}
if (N != 1) {
primeFact.put((int)N, 1);
}
return primeFact;
}
*/
/* ------------------- Binary Search ------------------- */
private static long factorial(int N) {
long ans = 1L;
for (int i = 2; i <= N; i++) {
ans *= i;
}
return ans;
}
private static long[] factorialDP(int N) {
long[] factDP = new long[N + 1];
factDP[0] = factDP[1] = 1;
for (int i = 2; i <= N; i++) {
factDP[i] = factDP[i - 1] * i;
}
return factDP;
}
private static long factorialMod(int N, int mod) {
long ans = 1L;
for (int i = 2; i <= N; i++) {
ans = ((ans % mod) * (i % mod)) % mod;
}
return ans;
}
/* ------------------- Binary Search ------------------- */
private static int floorSearch(int[] arr, int st, int ed, int tar) {
int ans = -1;
while (st <= ed) {
int mid = ((ed - st) >> 1) + st;
if (arr[mid] <= tar) {
ans = mid;
st = mid + 1;
} else {
ed = mid - 1;
}
}
return ans;
}
private static int ceilingSearch(int[] arr, int st, int ed, int tar) {
int ans = -1;
while (st <= ed) {
int mid = ((ed - st) >> 1) + st;
if (arr[mid] < tar) {
st = mid + 1;
} else {
ans = mid;
ed = mid - 1;
}
}
return ans;
}
/* ------------------- Power Function ------------------- */
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if ((y & 1) != 0) {
res = (res * x);
y--;
}
x = (x * x);
y >>= 1;
}
return res;
}
public static long powMod(long x, long y, int mod) {
long res = 1;
while (y > 0) {
if ((y & 1) != 0) {
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y >>= 1;
}
return res % mod;
}
/* ------------------- Disjoint Set(Union and Find) ------------------- */
private static class DSU {
public int[] parent, rank;
DSU(int N) {
parent = new int[N];
rank = new int[N];
for (int i = 0; i < N; i++) {
parent[i] = i;
rank[i] = 1;
}
}
public int find(int a) {
if (parent[a] == a) {
return a;
}
return parent[a] = find(parent[a]);
}
public boolean union(int a, int b) {
int parA = find(a), parB = find(b);
if (parA == parB) return false;
if (rank[parA] > rank[parB]) {
parent[parB] = parA;
} else if (rank[parA] < rank[parB]) {
parent[parA] = parB;
} else {
parent[parA] = parB;
rank[parB]++;
}
return true;
}
}
/* ------------------- Scanner class for input ------------------- */
private static class FasterScanner {
private InputStream stream;
private byte[] buffer = new byte[1024];
private int curChar, numChars;
private SpaceCharFilter filter;
public FasterScanner() {
// default
this.stream = System.in;
}
public FasterScanner(InputStream stream) {
this.stream = stream;
}
private int readChar() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buffer);
} catch (IOException e) {
throw new InputMismatchException(e.getMessage());
}
if (numChars <= 0) {
return -1;
}
}
return buffer[curChar++];
}
private boolean isWhiteSpace(int c) {
if (filter != null) {
return filter.isWhiteSpace(c);
}
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isNewLine(int ch) {
if (filter != null) {
return filter.isNewLine(ch);
}
return ch == '\r' || ch == '\n' || ch == -1;
}
public char nextChar() {
int ch = readChar();
char res = '\0';
while (isWhiteSpace(ch)) {
ch = readChar();
}
do {
res = (char)ch;
ch = readChar();
} while (!isWhiteSpace(ch));
return res;
}
public String next() {
int ch = readChar();
StringBuilder res = new StringBuilder();
while (isWhiteSpace(ch)) {
ch = readChar();
}
do {
res.appendCodePoint(ch);
ch = readChar();
} while (!isWhiteSpace(ch));
return res.toString();
}
public String nextLine() {
int ch = readChar();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(ch);
ch = readChar();
} while (!isNewLine(ch));
return res.toString();
}
public int nextInt() {
int ch = -1, sgn = 1, res = 0;
do {
ch = readChar();
} while (isWhiteSpace(ch));
if (ch == '-') {
sgn = -1;
ch = readChar();
}
do {
if (ch < '0' || ch > '9') {
throw new InputMismatchException("not a number");
}
res = (res * 10) + (ch - '0');
ch = readChar();
} while (!isWhiteSpace(ch));
return res * sgn;
}
public long nextLong() {
int ch = -1, sgn = 1;
long res = 0L;
do {
ch = readChar();
} while (isWhiteSpace(ch));
if (ch == '-') {
sgn = -1;
ch = readChar();
}
do {
if (ch < '0' || ch > '9') {
throw new InputMismatchException("not a number");
}
res = (10L * res) + (ch - '0');
ch = readChar();
} while (!isWhiteSpace(ch));
return 1L * res * sgn;
}
public double nextDouble() {
return Double.parseDouble(next());
}
/* for custom delimiters */
public interface SpaceCharFilter {
public boolean isWhiteSpace(int ch);
public boolean isNewLine(int ch);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | b1d25c09d088ecf2591245a7dde96e2b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
/**
* @author Naitik
*
*/
public class Main
{
static FastReader sc=new FastReader();
static int dp[][][];
//static int v[][];
static int mod=998244353;;
// static int mod=1000000007;
static long max;
static long bit[];
//static long bit1[];
// static long seg[];
//static long fact[];
// static long A[];
// static TreeMap<Integer,Integer> map;
//static StringBuffer sb=new StringBuffer("");
static HashMap<Long,Integer> map;
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args)
{
// StringBuffer sb=new StringBuffer("");
int ttt=1;
ttt =i();
outer :while (ttt-- > 0)
{
int n=i();
long k=l();
int A[]=input(n);
long B[]=new long[10];
B[0]=1;
HashMap<Integer,Integer> map=hash(A);
for(int i=1;i<10;i++) {
if(!map.containsKey(i)) {
B[i]=B[i-1];
}
else {
B[i]=power(10, i);
}
}
long D[]=new long[19];
for(int i=0;i<19;i++) {
D[i]=power(10, i);
}
long y=0;
int c=0;
while(true) {
y=9*D[c]+y;
long op1=go(y, B,D);
if(op1>k)
break;
c++;
}
char C[]=(y+"").toCharArray();
n=C.length-1;
long ans=Long.MAX_VALUE;
for(int i=0;i<C.length;i++) {
ans=y;
for(int j=9;j>=0;j--) {
long op1=y-j*D[n-i];
long go=go(op1, B,D);
if(go>k) {
ans=op1;
break;
}
}
y=ans;
}
out.println(y);
}
//System.out.println(sb.toString());
out.close();
//CHECK FOR N=1 //CHECK FOR M=0
//CHECK FOR N=1 //CHECK FOR M=0
//CHECK FOR N=1
}
static long go(long n,long A[],long C[]) {
long ans=0;
int c=0;
while(n>0) {
long y=n%10;
n/=10;
long r=y*C[c];
ans+=r/A[min(c,9)];
c++;
}
return ans;
}
static class Pair implements Comparable<Pair>
{
long x;
int y;
int z;
Pair(long x,int y){
this.x=x;
this.y=y;
// this.z=z;
}
@Override
public int compareTo(Pair o) {
if(this.x>o.x)
return +1;
else if(this.x<o.x)
return -1;
else {
if(this.y>o.y)
return 1;
else if(this.y<o.y)
return -1;
else
return 0;
}
}
// public int hashCode()
// {
// final int temp = 14;
// int ans = 1;
// ans =x*31+y*13;
// return ans;
// }
// @Override
// public boolean equals(Object o)
// {
// if (this == o) {
// return true;
// }
// if (o == null) {
// return false;
// }
// if (this.getClass() != o.getClass()) {
// return false;
// }
// Pair other = (Pair)o;
// if (this.x != other.x || this.y!=other.y) {
// return false;
// }
// return true;
// }
//
/* FOR TREE MAP PAIR USE */
// public int compareTo(Pair o) {
// if (x > o.x) {
// return 1;
// }
// if (x < o.x) {
// return -1;
// }
// if (y > o.y) {
// return 1;
// }
// if (y < o.y) {
// return -1;
// }
// return 0;
// }
}
//static int find(int A[],int a) {
// if(A[a]<0)
// return a;
// return A[a]=find(A, A[a]);
//}
static int find(int A[],int a) {
if(A[a]==a)
return a;
return find(A, A[a]);
}
//FENWICK TREE
static void update(int i, int x){
for(; i < bit.length; i += (i&-i))
bit[i] += x;
}
static int sum(int i){
int ans = 0;
for(; i > 0; i -= (i&-i))
ans += bit[i];
return ans;
}
//END
static void add(long v) {
if(!map.containsKey(v)) {
map.put(v, 1);
}
else {
map.put(v, map.get(v)+1);
}
}
static void remove(long v) {
if(map.containsKey(v)) {
map.put(v, map.get(v)-1);
if(map.get(v)==0)
map.remove(v);
}
}
public static int upper(int A[],int k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A[mid]<=k) {
ans=mid;
l=mid+1;
}
else {
u=mid-1;
}
}
return ans;
}
public static int lower(int A[],int k,int si,int ei)
{
int l=si;
int u=ei;
int ans=-1;
while(l<=u) {
int mid=(l+u)/2;
if(A[mid]<=k) {
l=mid+1;
}
else {
ans=mid;
u=mid-1;
}
}
return ans;
}
static int[] copy(int A[]) {
int B[]=new int[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static long[] copy(long A[]) {
long B[]=new long[A.length];
for(int i=0;i<A.length;i++) {
B[i]=A[i];
}
return B;
}
static int[] input(int n) {
int A[]=new int[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextInt();
}
return A;
}
static long[] inputL(int n) {
long A[]=new long[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextLong();
}
return A;
}
static String[] inputS(int n) {
String A[]=new String[n];
for(int i=0;i<n;i++) {
A[i]=sc.next();
}
return A;
}
static long sum(int A[]) {
long sum=0;
for(int i : A) {
sum+=i;
}
return sum;
}
static long sum(long A[]) {
long sum=0;
for(long i : A) {
sum+=i;
}
return sum;
}
static void reverse(long A[]) {
int n=A.length;
long B[]=new long[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static void reverse(int A[]) {
int n=A.length;
int B[]=new int[n];
for(int i=0;i<n;i++) {
B[i]=A[n-i-1];
}
for(int i=0;i<n;i++)
A[i]=B[i];
}
static void input(int A[],int B[]) {
for(int i=0;i<A.length;i++) {
A[i]=sc.nextInt();
B[i]=sc.nextInt();
}
}
static int[][] input(int n,int m){
int A[][]=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
A[i][j]=i();
}
}
return A;
}
static char[][] charinput(int n,int m){
char A[][]=new char[n][m];
for(int i=0;i<n;i++) {
String s=s();
for(int j=0;j<m;j++) {
A[i][j]=s.charAt(j);
}
}
return A;
}
static int max(int A[]) {
int max=Integer.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static int min(int A[]) {
int min=Integer.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long max(long A[]) {
long max=Long.MIN_VALUE;
for(int i=0;i<A.length;i++) {
max=Math.max(max, A[i]);
}
return max;
}
static long min(long A[]) {
long min=Long.MAX_VALUE;
for(int i=0;i<A.length;i++) {
min=Math.min(min, A[i]);
}
return min;
}
static long [] prefix(long A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] prefix(int A[]) {
long p[]=new long[A.length];
p[0]=A[0];
for(int i=1;i<A.length;i++)
p[i]=p[i-1]+A[i];
return p;
}
static long [] suffix(long A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static long [] suffix(int A[]) {
long p[]=new long[A.length];
p[A.length-1]=A[A.length-1];
for(int i=A.length-2;i>=0;i--)
p[i]=p[i+1]+A[i];
return p;
}
static void fill(int dp[]) {
Arrays.fill(dp, -1);
}
static void fill(int dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(int dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(int dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static void fill(long dp[]) {
Arrays.fill(dp, -1);
}
static void fill(long dp[][]) {
for(int i=0;i<dp.length;i++)
Arrays.fill(dp[i], -1);
}
static void fill(long dp[][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
Arrays.fill(dp[i][j],-1);
}
}
}
static void fill(long dp[][][][]) {
for(int i=0;i<dp.length;i++) {
for(int j=0;j<dp[0].length;j++) {
for(int k=0;k<dp[0][0].length;k++) {
Arrays.fill(dp[i][j][k],-1);
}
}
}
}
static int min(int a,int b) {
return Math.min(a, b);
}
static int min(int a,int b,int c) {
return Math.min(a, Math.min(b, c));
}
static int min(int a,int b,int c,int d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static int max(int a,int b) {
return Math.max(a, b);
}
static int max(int a,int b,int c) {
return Math.max(a, Math.max(b, c));
}
static int max(int a,int b,int c,int d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long min(long a,long b) {
return Math.min(a, b);
}
static long min(long a,long b,long c) {
return Math.min(a, Math.min(b, c));
}
static long min(long a,long b,long c,long d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static long max(long a,long b) {
return Math.max(a, b);
}
static long max(long a,long b,long c) {
return Math.max(a, Math.max(b, c));
}
static long max(long a,long b,long c,long d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long power(long x, long y, long p)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long power(long x, long y)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
static void print(int A[]) {
for(int i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(long A[]) {
for(long i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static long mod(long x) {
return ((x%mod + mod)%mod);
}
static String reverse(String s) {
StringBuffer p=new StringBuffer(s);
p.reverse();
return p.toString();
}
static int i() {
return sc.nextInt();
}
static String s() {
return sc.next();
}
static long l() {
return sc.nextLong();
}
static void sort(int[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
int tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static void sort(long[] A){
int n = A.length;
Random rnd = new Random();
for(int i=0; i<n; ++i){
long tmp = A[i];
int randomPos = i + rnd.nextInt(n-i);
A[i] = A[randomPos];
A[randomPos] = tmp;
}
Arrays.sort(A);
}
static String sort(String s) {
Character ch[]=new Character[s.length()];
for(int i=0;i<s.length();i++) {
ch[i]=s.charAt(i);
}
Arrays.sort(ch);
StringBuffer st=new StringBuffer("");
for(int i=0;i<s.length();i++) {
st.append(ch[i]);
}
return st.toString();
}
static HashMap<Integer,Integer> hash(int A[]){
HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static HashMap<Long,Integer> hash(long A[]){
HashMap<Long,Integer> map=new HashMap<Long, Integer>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static TreeMap<Integer,Integer> tree(int A[]){
TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>();
for(int i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static TreeMap<Long,Integer> tree(long A[]){
TreeMap<Long,Integer> map=new TreeMap<Long, Integer>();
for(long i : A) {
if(map.containsKey(i)) {
map.put(i, map.get(i)+1);
}
else {
map.put(i, 1);
}
}
return map;
}
static boolean prime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean prime(long n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 5ef2ae77ec0b72238344ad9093dce583 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
//import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar;
import java.lang.*;
import java.io.*;
public class Main
{
public static class FastReader {
BufferedReader b;
StringTokenizer s;
public FastReader() {
b=new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(s==null ||!s.hasMoreElements()) {
try {
s=new StringTokenizer(b.readLine());
}
catch(IOException e) {
e.printStackTrace();
}
}
return s.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str="";
try {
str=b.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (s != null && s.hasMoreTokens()) {
return true;
}
String tmp;
try {
b.mark(1000);
tmp = b.readLine();
if (tmp == null) {
return false;
}
b.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
public static long gcd(long a,long b) {if(a==0)return b; return gcd(b%a,a);}
public static int gcd(int a,int b) {if(a==0)return b; return gcd(b%a,a);};
static int power(int x, int y){
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
static long power(long x , long y)
{
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
public static void main (String[] args) throws java.lang.Exception
{
long mod=1000000007;
FastReader in=new FastReader();
if(in.hasNext()){
if(in.hasNext()){
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
int test=in.nextInt();
while(test-->0)
{
int n=in.nextInt();
long k=in.nextLong();
k++;
long arr[]=new long[n];
for(int i=0;i<n;i++)
{
long t=in.nextLong();
arr[i]=t;
}
long fk=0,tk=0;
long term=0;
int i=0;
while(i<n-1)
{
tk=power((long)10,arr[i+1]-arr[i])-(long)1;
fk+=tk;
if(fk>=k) {fk-=tk;
break;}
term+=tk*power((long)10,arr[i]);
i++;
}
term+=power((long)10,arr[i])*(k-fk);
//term+=power((long)10,arr[i])*(k-fk);
System.out.println(term);
log.flush();
}
}
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | e1d9c3b96bedb87e121ab73536732da4 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Banknotes {
static FastScanner fs;
static FastWriter fw;
static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null;
private static final int mod = (int) (1e9 + 7);
public static void main(String[] args) throws IOException {
fs = new FastScanner();
fw = new FastWriter();
int t = 1;
t = fs.nextInt();
while (t-- > 0) {
solve();
}
fw.out.close();
}
static void solve() {
int n = fs.nextInt(), k = fs.nextInt();
ArrayList<Integer> tenPows = new ArrayList<>();
for (int i = 0; i < n; i++) {
int ai = fs.nextInt();
tenPows.add(pow(10, ai));
}
long result = 0;
int req = k + 1;
for (int i = 0; i < (n - 1); i++) {
int max = ((tenPows.get(i + 1)) / tenPows.get(i)) - 1;
int taken = Math.min(max, req);
result += ((long) taken * tenPows.get(i));
req -= taken;
}
result += ((long) req * tenPows.get(n - 1));
fw.out.println(result);
}
private static int pow(int a, int b) {
int result = 1;
while (b > 0) {
if ((b & 1) == 1) {
result = (result * a);
}
a *= a;
b >>= 1;
}
return result;
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() throws IOException {
if (checkOnlineJudge)
this.br = new BufferedReader(new FileReader("src/input.txt"));
else
this.br = new BufferedReader(new InputStreamReader(System.in));
this.st = new StringTokenizer("");
}
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException err) {
err.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() {
if (st.hasMoreTokens()) {
return st.nextToken("").trim();
}
try {
return br.readLine().trim();
} catch (IOException err) {
err.printStackTrace();
}
return "";
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
private static class FastWriter {
PrintWriter out;
FastWriter() throws IOException {
if (checkOnlineJudge)
out = new PrintWriter(new FileWriter("src/output.txt"));
else
out = new PrintWriter(System.out);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 76a20aa614f37ed55d5e981fd279ed47 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Solution{
static int max(int[] arr,int n){
int mx = Integer.MIN_VALUE;
for(int i = 0;i < n;i++){
if(arr[i] > mx){
mx = arr[i];
}
}
return mx;
}
static int min(int[] arr,int n){
int mn = Integer.MAX_VALUE;
for(int i = 0;i < n;i++){
if(arr[i] < mn){
mn = arr[i];
}
}
return mn;
}
static long binexp(long a,long b){
long ans = 1;
while(b > 0){
if((b & 1l) == 1l) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static void sort(int[] arr) {
ArrayList<Integer> l = new ArrayList<>();
for (int i:arr) l.add(i);
Collections.sort(l);
for (int i = 0; i < arr.length; i++) arr[i] = l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
int[] int_arr(int n){
int arr[] = new int[n];
for(int i = 0;i < n;i++) arr[i] = nextInt();
return arr;
}
long[] l_arr(int n){
long arr[] = new long[n];
for(int i = 0;i < n;i++) arr[i] = nextLong();
return arr;
}
}
static int bound(int[] arr,int start,int end,int x,boolean lower){
int ans = -1;
while(start <= end){
int mid = start + (end - start) / 2;
if(arr[mid] > x) end = mid - 1;
else if(arr[mid] < x) start = mid + 1;
else{
ans = mid;
if(lower) end = mid - 1;
else start = mid + 1;
}
}
return ans;
}
static boolean isPrime(int n){
if(n == 1){
return false;
}
if(n == 2 || n == 3){
return true;
}
if(n % 2 == 0 || n % 3 == 0){
return false;
}
for(long i = 5; i*i <= n; i += 6){
if(n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
static int gcd(int a,int b){
return (a == 0) ? b : gcd(b % a,a);
}
static int l = 10000000;
static boolean[] sieve = new boolean[l+1];
static void primes(){
Arrays.fill(sieve,true);
for(int i = 2;i * i <= l;i++){
if(sieve[i]){
for(int j = i * i;j <= l;j += i){
sieve[j] = false;
}
}
}
}
public int bs(int[] arr,int start,int end,int target){
while(start <= end){
int mid = start + (end - start) / 2;
if(arr[mid] == target){
return mid;
}
else if(arr[mid] > target){
end = mid - 1;
}
else{
start = mid + 1;
}
}
return -1;
}
public static void main(String[] args){
FastScanner in = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t --> 0){
long n = in.nextLong(),k = in.nextLong();
long[] arr = new long[(int)n];
for(int i = 0;i < (int)n;i++) arr[i] = binexp(10l,in.nextLong());
long tot = 0;
k += 1;
for(int i = 1;i < (int)n;i++){
long val = (arr[i] / arr[i - 1]) - 1;
if(val < k){
tot += val * arr[i - 1];
}
else{
tot += k * arr[i - 1];
}
k -= val;
if(k <= 0) break;
}
if(k > 0){
tot += k * arr[(int)n - 1];
}
out.println(tot);
}
out.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4a196827c5f74a52a5d3c47ef4d30028 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class codeforcesB{
public static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]){
FastReader sc=new FastReader();
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int k=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++){ar[i]=sc.nextInt();}
Arrays.sort(ar);
for(int i=0;i<n;i++){ar[i]=(int)Math.pow(10,ar[i]);}
long ans=0;int req=k+1;
for(int i=1;i<n;i++){
int max=(ar[i]-ar[i-1])/ar[i-1];
max=Math.min(req,max);
req-=max;
ans+=(max*ar[i-1]);
}
ans+=((long)req*(long)ar[n-1]);
System.out.println(ans);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 9786805099844d44cc751351270800f2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class c {
public static void main(String[] args){
FastScanner sc = new FastScanner();
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
long k = sc.nextLong();
k++;
long arr[] = new long[n];
for(int i=0; i<n; i++){
arr[i] = (long)Math.pow(10, sc.nextLong());
}
long currentNum = 0;
long notes = 0;
for(int i=0; i<n-1; i++){
if(notes == k) break;
if(k - notes >= arr[i+1]/arr[i]-1){
notes += arr[i+1]/arr[i]-1;
currentNum += arr[i] * (arr[i+1]/arr[i]-1);
}
else{
currentNum += (k-notes)*arr[i];
notes += k-notes;
}
// System.out.println("Notes: " + notes + " CurrentNUm: " + currentNum);
}
if(notes < k){
currentNum += (k-notes) * arr[arr.length-1];
}
System.out.println(currentNum);
}
}
}
class FastScanner {
//I don't understand how this works lmao
private int BS = 1 << 16;
private char NC = (char) 0;
private byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
public FastScanner(String s) {
try {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
} catch (Exception e) {
in = new BufferedInputStream(System.in, BS);
}
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
public String next() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c > 32) {
res.append(c);
c = getChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
public boolean hasNext() {
if (c > 32) return true;
while (true) {
c = getChar();
if (c == NC) return false;
else if (c > 32) return true;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | f1bd6d940ec1b8226804ed49b2aaaf75 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
//--------------------------INPUT READER--------------------------------//
static class fs {
public BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public fs() { this(System.in); }
public fs(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
String next() {
while (!st.hasMoreTokens()) {
try { st = new StringTokenizer(br.readLine()); }
catch (IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
int ni() { return Integer.parseInt(next()); }
long nl() { return Long.parseLong(next()); }
double nd() { return Double.parseDouble(next()); }
String ns() { return next(); }
int[] na(long nn) {
int n = (int) nn;
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
long[] nal(long nn) {
int n = (int) nn;
long[] l = new long[n];
for(int i = 0; i < n; i++) l[i] = nl();
return l;
}
}
//-----------------------------------------------------------------------//
//---------------------------PRINTER-------------------------------------//
static class Printer {
static PrintWriter w;
public Printer() {this(System.out);}
public Printer(OutputStream os) {
w = new PrintWriter(os);
}
public void p(int i) {w.println(i);};
public void p(long l) {w.println(l);};
public void p(double d) {w.println(d);};
public void p(String s) { w.println(s);};
public void pr(int i) {w.print(i);};
public void pr(long l) {w.print(l);};
public void pr(double d) {w.print(d);};
public void pr(String s) { w.print(s);};
public void pl() {w.println();};
public void close() {w.close();};
}
//------------------------------------------------------------------------//
//--------------------------VARIABLES------------------------------------//
static fs sc = new fs();
static OutputStream outputStream = System.out;
static Printer w = new Printer(outputStream);
//-----------------------------------------------------------------------//
//--------------------------ADMIN_MODE-----------------------------------//
private static void ADMIN_MODE() throws IOException {
if (System.getProperty("ONLINE_JUDGE") == null) {
w = new Printer(new FileOutputStream("output.txt"));
sc = new fs(new FileInputStream("input.txt"));
}
}
//-----------------------------------------------------------------------//
//----------------------------START--------------------------------------//
public static void main(String[] args)
throws IOException {
ADMIN_MODE();
int t = sc.ni();while(t-->0)
solve();
w.close();
}
// region pow(a, b, mod) -> a^b
static long mp (long b, long x) {
if (x == 0) return 1;
if (x == 1) return b;
long mod = Long.MAX_VALUE;
if (x % 2 == 0) return mp (b * b % mod, x / 2) % mod;
return b * mp (b * b % mod, x / 2) % mod;
}
// endregion
static void solve() throws IOException {
long n = sc.nl(), k = sc.nl();
long[] types = new long[(int)n];
for(int i = 0; i < n; i++) {
types[i] = mp(10, sc.ni());
}
long used = 0, val = 0;
int i = 0;
for(i = 0; i < n-1; i++) {
long curr = types[i+1]/types[i]-1;
if(used+curr > k) {
val += (k-used)*types[i];
used = k;
break;
}
used += curr;
val += curr*types[i];
}
if(i == n) {
i--;
}
val+=types[i]*(k-used+1);
w.p(val);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 474644c7756c6b50a08c32348a05e0b2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
public class SolnC {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++) {
int n=sc.nextInt();
int k=sc.nextInt();
k++;
int[] a = new int[n];
for(int j=0;j<n;j++) {
a[j]=sc.nextInt();
}
long res = 0L;
for(int j=0;j<n-1;j++) {
if(k>0) {
long ans = (long) (Math.pow(10, a[j+1]-a[j])-1);
long best = Math.min(ans, k);
res=(long) Math.pow(10, a[j])*best+res;
k-=best;
}
}
if(k>0) {
res=res+(long) Math.pow(10, a[n-1])*k;
}
System.out.println(res);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d64638bb3bcb371b79a0930c58410241 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
public class Solution {
public static boolean Local(){
try{
return System.getenv("LOCAL_SYS")!=null;
}catch(Exception e){
return false;
}
}
public static boolean LOCAL;
static class FastScanner {
BufferedReader br;
StringTokenizer st ;
FastScanner(){
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
}
FastScanner(String file) {
try{
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
st = new StringTokenizer("");
}catch(FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
e.printStackTrace();
}
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
String readLine() throws IOException{
return br.readLine();
}
}
static class Pair<T,X> {
T first;
X second;
Pair(T first,X second){
this.first = first;
this.second = second;
}
@Override
public int hashCode(){
return Objects.hash(first,second);
}
@Override
public boolean equals(Object obj){
return obj.hashCode() == this.hashCode();
}
}
static PrintStream debug = null;
static long mod = (long)(Math.pow(10,9) + 7);
public static void main(String[] args) throws Exception {
FastScanner s = new FastScanner();
LOCAL = Local();
//PrintWriter pw = new PrintWriter(System.out);
if(LOCAL){
s = new FastScanner("src/input.txt");
PrintStream o = new PrintStream("src/sampleout.txt");
debug = new PrintStream("src/debug.txt");
System.setOut(o);
// pw = new PrintWriter(o);
}
long mod = 1000000007;
int tcr = s.nextInt();
StringBuilder sb = new StringBuilder();
for(int tc=0;tc<tcr;tc++){
int n = s.nextInt();
long k = s.nextLong();
int arr[] = new int[n];
k++;
for(int i=0;i<n;i++){
arr[i] = s.nextInt();
}
long ans = 0;
long max_used[] = new long[n];
Arrays.fill(max_used,Long.MAX_VALUE);
for(int i=0;i<n-1;i++){
max_used[i] = (long)((modpow(10,arr[i+1],Long.MAX_VALUE) - modpow(10,arr[i],Long.MAX_VALUE))/modpow(10,arr[i],Long.MAX_VALUE));
}
dbg(debug,max_used);
for(int i=0;i<n-1;i++){
if(max_used[i] <= k){
ans += (max_used[i]*Math.pow(10,arr[i]));
k-=max_used[i];
}else{
ans += (k*modpow(10,arr[i],Long.MAX_VALUE));
//println(i);
k = 0;break;
}
}
//println(Long.MAX_VALUE);
// int len = len(k);
// println(k+"--"+((k*Math.pow(10,len)))+" "+ans);
// println(((k*Math.pow(10,len)))+ans);
if(k > 0){
ans += (k*modpow(10,arr[n-1],Long.MAX_VALUE));
}
sb.append(ans+"\n");
}
print(sb.toString());
}
public static int justGreater(long arr[],long num,int st,long mag_dec){
// int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if((arr[mid] - mag_dec) <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static List<int[]> print_prime_factors(int n){
List<int[]> list = new ArrayList<>();
for(int i=2;i<=(int)(Math.sqrt(n));i++){
if(n % i == 0){
int cnt = 0;
while( (n % i) == 0){
n = n/i;
cnt++;
}
list.add(new int[]{i,cnt});
}
}
if(n!=1){
list.add(new int[]{n,1});
}
return list;
}
public static boolean inRange(int r1,int r2,int val){
return ((val >= r1) && (val <= r2));
}
static int len(long num){
return Long.toString(num).length();
}
static long mulmod(long a, long b,long mod)
{
long ans = 0l;
while(b > 0){
long curr = (b & 1l);
if(curr == 1l){
ans = ((ans % mod) + a) % mod;
}
a = (a + a) % mod;
b = b >> 1;
}
return ans;
}
public static void dbg(PrintStream ps,Object... o) throws Exception{
if(ps == null){
return;
}
Debug.dbg(ps,o);
}
public static long modpow(long num,long pow,long mod){
long val = num;
long ans = 1l;
while(pow > 0l){
long bit = pow & 1l;
if(bit == 1){
ans = (ans * (val%mod))%mod;
}
val = (val * val) % mod;
pow = pow >> 1;
}
return ans;
}
public static char get(int n){
return (char)('a' + n);
}
public static long[] sort(long arr[]){
List<Long> list = new ArrayList<>();
for(long n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
public static int[] sort(int arr[]){
List<Integer> list = new ArrayList<>();
for(int n : arr){list.add(n);}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i] = list.get(i);
}
return arr;
}
// return the (index + 1)
// where index is the pos of just smaller element
// i.e count of elemets strictly less than num
public static int justSmaller(long arr[],long num){
// System.out.println(num+"@");
int st = 0;
int e = arr.length - 1;
int ans = -1;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] >= num){
e = mid - 1;
}else{
ans = mid;
st = mid + 1;
}
}
return ans + 1;
}
public static int justSmaller(int arr[],int num){
// System.out.println(num+"@");
int st = 0;
int e = arr.length - 1;
int ans = -1;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] >= num){
e = mid - 1;
}else{
ans = mid;
st = mid + 1;
}
}
return ans + 1;
}
//return (index of just greater element)
//count of elements smaller than or equal to num
public static int justGreater(long arr[],long num){
int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static int justGreater(int arr[],int num){
int st = 0;
int e = arr.length - 1;
int ans = arr.length;
while(st <= e){
int mid = (st + e)/2;
if(arr[mid] <= num){
st = mid + 1;
}else{
ans = mid;
e = mid - 1;
}
}
return ans;
}
public static void println(Object obj){
System.out.println(obj.toString());
}
public static void print(Object obj){
System.out.print(obj.toString());
}
public static int gcd(int a,int b){
if(b == 0){return a;}
return gcd(b,a%b);
}
public static long gcd(long a,long b){
if(b == 0l){
return a;
}
return gcd(b,a%b);
}
public static int find(int parent[],int v){
if(parent[v] == v){
return v;
}
return parent[v] = find(parent, parent[v]);
}
public static List<Integer> sieve(){
List<Integer> prime = new ArrayList<>();
int arr[] = new int[100001];
Arrays.fill(arr,1);
arr[1] = 0;
arr[2] = 1;
for(int i=2;i<=100000;i++){
if(arr[i] == 1){
prime.add(i);
for(long j = (i*1l*i);j<100001;j+=i){
arr[(int)j] = 0;
}
}
}
return prime;
}
static boolean isPower(long n,long a){
long log = (long)(Math.log(n)/Math.log(a));
long power = (long)Math.pow(a,log);
if(power == n){return true;}
return false;
}
private static int mergeAndCount(int[] arr, int l,int m, int r)
{
// Left subarray
int[] left = Arrays.copyOfRange(arr, l, m + 1);
// Right subarray
int[] right = Arrays.copyOfRange(arr, m + 1, r + 1);
int i = 0, j = 0, k = l, swaps = 0;
while (i < left.length && j < right.length) {
if (left[i] <= right[j])
arr[k++] = left[i++];
else {
arr[k++] = right[j++];
swaps += (m + 1) - (l + i);
}
}
while (i < left.length)
arr[k++] = left[i++];
while (j < right.length)
arr[k++] = right[j++];
return swaps;
}
// Merge sort function
private static int mergeSortAndCount(int[] arr, int l,int r)
{
// Keeps track of the inversion count at a
// particular node of the recursion tree
int count = 0;
if (l < r) {
int m = (l + r) / 2;
// Total inversion count = left subarray count
// + right subarray count + merge count
// Left subarray count
count += mergeSortAndCount(arr, l, m);
// Right subarray count
count += mergeSortAndCount(arr, m + 1, r);
// Merge count
count += mergeAndCount(arr, l, m, r);
}
return count;
}
static class Debug{
//change to System.getProperty("ONLINE_JUDGE")==null; for CodeForces
public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;
private static <T> String ts(T t) {
if(t==null) {
return "null";
}
try {
return ts((Iterable) t);
}catch(ClassCastException e) {
if(t instanceof int[]) {
String s = Arrays.toString((int[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof long[]) {
String s = Arrays.toString((long[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof char[]) {
String s = Arrays.toString((char[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof double[]) {
String s = Arrays.toString((double[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}else if(t instanceof boolean[]) {
String s = Arrays.toString((boolean[]) t);
return "{"+s.substring(1, s.length()-1)+"}\n";
}
try {
return ts((Object[]) t);
}catch(ClassCastException e1) {
return t.toString();
}
}
}
private static <T> String ts(T[] arr) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: arr) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}");
return ret.toString();
}
private static <T> String ts(Iterable<T> iter) {
StringBuilder ret = new StringBuilder();
ret.append("{");
boolean first = true;
for(T t: iter) {
if(!first) {
ret.append(", ");
}
first = false;
ret.append(ts(t));
}
ret.append("}\n");
return ret.toString();
}
public static void dbg(PrintStream ps,Object... o) throws Exception {
if(LOCAL) {
System.setErr(ps);
System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [\n");
for(int i = 0; i<o.length; i++) {
if(i!=0) {
System.err.print(", ");
}
System.err.print(ts(o[i]));
}
System.err.println("]");
}
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | edddaaa1ce82c8d7ab4300bf60fec0f8 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import java.math.*;
public class Main{
public static void main(String[] args) {
TaskA solver = new TaskA();
// boolean[]prime=seive(3*100001);
int t = in.nextInt();
for (int i = 1; i <= t ; i++) {
solver.solve(i, in, out);
}
// solver.solve(1, in, out);
out.flush();
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n= in.nextInt();
int k= in.nextInt()+1;
long []arr=new long[n];
for(int i=0;i<n;i++) {
arr[i]=(long)Math.pow(10, in.nextInt());
}
int count=0;long ans=0;int i=0;
for( i=0;i<n-1&&count<k;i++) {
count+=((arr[i+1]/(arr[i])-1));
ans+=((arr[i+1]/arr[i])-1)*arr[i];
}
if(count<k) {
ans+=(k-count)*arr[i];
}
else {
ans-=(count-k)*arr[i-1];
}
System.out.println(ans);
}
}
static int net(int []arr,int index,int num) {
int count=0;
for(int i=index;i>=0;i--) {
count += num/Math.pow(10, arr[i]);
num%=Math.pow(10, arr[index]);
}
return count;
}
static long pow(long b, long e) {
long ans = 1;
while (e > 0) {
if (e % 2 == 1)
ans = ans * b % mod;
e >>= 1;
b = b * b % mod;
}
return ans;
}
static int[]dp; //global variable
static int minStep(int n) {
if(n<0) {
return Integer.MAX_VALUE; //this is never possible should be handled bcz n-1,n-5 can be negative
}
if(n==0) {return 0;}
if(dp[n]!=0) {
return dp[n]; //if solution we have already calculated
}
else {
int x=1+Math.min(minStep(n-1),Math.min(minStep(n-3),minStep(n-5)));
dp[n]=x; //update the array after calculation
return x;
}
}
static void sortF(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return p1.second-p2.second;
}
return p1.first - p2.first;
}
});
}
static int[] shift (int[]inp,int i,int j){
int[]arr=new int[j-i+1];
int n=j-i+1;
for(int k=i;k<=j;k++) {
arr[(k-i+1)%n]=inp[k];
}
for(int k=0;k<n;k++ ) {
inp[k+i]=arr[k];
}
return inp;
}
static int sumDigits(long n) {
int total=0;
while(n!=0) {
total+=n%10;
n=n/10;
}
return total;
}
static long[] fac;
static long mod = (long) 1000000007;
static void initFac(long n) {
fac = new long[(int)n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
}
static long nck(int n, int k) {
if (n < k)
return 0;
long den = inv((int) (fac[k] * fac[n - k] % mod));
return fac[n] * den % mod;
}
static int[]MakeArr(int n){
int[]arr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=in.nextInt();
}
return arr;
}
static int[]arr(){
int n= in.nextInt();
int[]arr=new int[n];
for(int i=0;i<n;i++) {
arr[i]=in.nextInt();
}
return arr;
}
static long inv(long x) {
return pow(x, mod - 2);
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) {
Queue<Integer>q=new LinkedList<>();
q.add(source);
visited[source]=true;
int distance=0;
while(!q.isEmpty()) {
int curr=q.poll();
distance++;
for(int neighbour:a[curr]) {
if(!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
}
}
}
return distance;
}
public static Set<Integer>factors(int n){
Set<Integer>ans=new HashSet<>();
ans.add(1);
for(int i=2;i*i<=n;i++) {
if(n%i==0) {
ans.add(i);
ans.add(n/i);
}
}
return ans;
}
public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) {
boolean[]visited=new boolean[a.length];
int[]parent=new int[a.length];
Queue<Integer>q=new LinkedList<>();
int distance=0;
q.add(source);
visited[source]=true;
parent[source]=-1;
while(!q.isEmpty()) {
int curr=q.poll();
if(curr==destination) {
break;
}
for(int neighbour:a[curr]) {
if(neighbour!=-1&&!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
parent[neighbour]=curr;
}
}
}
int cur=destination;
while(parent[cur]!=-1) {
distance++;
cur=parent[cur];
}
return distance;
}
static int bs(int size,int[]arr) {
int x = -1;
for (int b = size/2; b >= 1; b /= 2) {
while (!ok(arr));
}
int k = x+1;
return k;
}
static boolean ok(int[]x) {
return false;
}
public static int solve1(ArrayList<Integer> A) {
long[]arr =new long[A.size()+1];
int n=A.size();
for(int i=1;i<=A.size();i++) {
arr[i]=((i%2)*((n-i+1)%2))%2;
arr[i]%=2;
}
int ans=0;
for(int i=0;i<A.size();i++) {
if(arr[i+1]==1) {
ans^=A.get(i);
}
}
return ans;
}
public static String printBinary(long a) {
String str="";
for(int i=31;i>=0;i--) {
if((a&(1<<i))!=0) {
str+=1;
}
if((a&(1<<i))==0 && !str.isEmpty()) {
str+=0;
}
}
return str;
}
public static String reverse(long a) {
long rev=0;
String str="";
int x=(int)(Math.log(a)/Math.log(2))+1;
for(int i=0;i<32;i++) {
rev<<=1;
if((a&(1<<i))!=0) {
rev|=1;
str+=1;
}
else {
str+=0;
}
}
return str;
}
////////////////////////////////////////////////////////
static void sortS(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
return p1.second - p2.second;
}
});
}
static class Pair implements Comparable<Pair>
{
int first ;int second ;
public Pair(int x, int y)
{
this.first = x ;this.second = y ;
}
@Override
public boolean equals(Object obj)
{
if(obj == this)return true ;
if(obj == null)return false ;
if(this.getClass() != obj.getClass()) return false ;
Pair other = (Pair)(obj) ;
if(this.first != other.first)return false ;
if(this.second != other.second)return false ;
return true ;
}
@Override
public int hashCode()
{
return this.first^this.second ;
}
@Override
public String toString() {
String ans = "" ;ans += this.first ; ans += " "; ans += this.second ;
return ans ;
}
@Override
public int compareTo(Main.Pair o) {
{ if(this.first==o.first) {
return this.second-o.second;
}
return this.first - o.first;
}
}
}
//////////////////////////////////////////////////////////////////////////
static int nD(long num) {
String s=String.valueOf(num);
return s.length();
}
static int CommonDigits(int x,int y) {
String s=String.valueOf(x);
String s2=String.valueOf(y);
return 0;
}
static int lcs(String str1, String str2, int m, int n)
{
int L[][] = new int[m + 1][n + 1];
int i, j;
// Following steps build L[m+1][n+1] in
// bottom up fashion. Note that L[i][j]
// contains length of LCS of str1[0..i-1]
// and str2[0..j-1]
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (str1.charAt(i - 1)
== str2.charAt(j - 1))
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = Math.max(L[i - 1][j],
L[i][j - 1]);
}
}
// L[m][n] contains length of LCS
// for X[0..n-1] and Y[0..m-1]
return L[m][n];
}
/////////////////////////////////
boolean IsPowerOfTwo(int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}
////////////////////////////////
static long power(long a,long b,long m ) {
long ans=1;
while(b>0) {
if(b%2==1) {
ans=((ans%m)*(a%m))%m; b--;
}
else {
a=(a*a)%m;b/=2;
}
}
return ans%m;
}
///////////////////////////////
public static boolean repeatedSubString(String string) {
return ((string + string).indexOf(string, 1) != string.length());
}
static int search(char[]c,int start,int end,char x) {
for(int i=start;i<end;i++) {
if(c[i]==x) {return i;}
}
return -2;
}
////////////////////////////////
static int gcd(int a, int b) {
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
return a;
}
static long fac(long a)
{
if(a== 0L || a==1L)return 1L ;
return a*fac(a-1L) ;
}
static ArrayList al() {
ArrayList<Integer>a =new ArrayList<>();
return a;
}
static HashSet h() {
return new HashSet<Integer>();
}
static void debug(int[][]a) {
int n= a.length;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
out.print(a[i][j]+" ");
}
out.print("\n");
}
}
static void debug(int[]a) {
out.println(Arrays.toString(a));
}
static void debug(ArrayList<Integer>a) {
out.println(a.toString());
}
static boolean[]seive(int n){
boolean[]b=new boolean[n+1];
for (int i = 2; i <= n; i++)
b[i] = true;
for(int i=2;i*i<=n;i++) {
if(b[i]) {
for(int j=i*i;j<=n;j+=i) {
b[j]=false;
}
}
}
return b;
}
static int longestIncreasingSubseq(int[]arr) {
int[]sizes=new int[arr.length];
Arrays.fill(sizes, 1);
int max=1;
for(int i=1;i<arr.length;i++) {
for(int j=0;j<i;j++) {
if(arr[j]<arr[i]) {
sizes[i]=Math.max(sizes[i],sizes[j]+1);
max=Math.max(max, sizes[i]);
}
}
}
return max;
}
public static ArrayList primeFactors(long n)
{
ArrayList<Long>h= new ArrayList<>();
// Print the number of 2s that divide n
if(n%2 ==0) {h.add(2L);}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (long i = 3; i <= Math.sqrt(n); i+= 2)
{
if(n%i==0) {h.add(i);}
}
if (n > 2)
h.add(n);
return h;
}
static boolean Divisors(long n){
if(n%2==1) {
return true;
}
for (long i=2; i<=Math.sqrt(n); i++){
if (n%i==0 && i%2==1){
return true;
}
}
return false;
}
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static InputReader in = new InputReader(inputStream);
static PrintWriter out = new PrintWriter(outputStream);
public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
if(i==a.length) {
al.add(s);
return;
}
superSet(a,al,i+1,s);
superSet(a,al,i+1,s+a[i]+" ");
}
public static long[] makeArr() {
long size=in.nextInt();
long []arr=new long[(int)size];
for(int i=0;i<size;i++) {
arr[i]=in.nextInt();
}
return arr;
}
public static long[] arr(int n) {
long []arr=new long[n+1];
for(int i=1;i<n+1;i++) {
arr[i]=in.nextLong();
}
return arr;
}
public static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
static void print(int c) {
out.print(c);
}
static void println(int x) {
out.println(x);
}
static void print(String s) {
out.print(s);
}
static void println(String s) {
out.println(s);
}
public static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
public static void reverse(int[] array)
{
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}
public static long nCr(int n,int k)
{
long ans=1L;
k=k>n-k?n-k:k;
for( int j=1;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
static int searchMax(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]>inp[index]) {
index+=1;
}
return index;
}
static int searchMin(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]<inp[index]) {
index+=1;
}
return index;
}
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
static class Pairr implements Comparable<Pairr>{
private int index;
private int cumsum;
private ArrayList<Integer>indices;
public Pairr(int index,int cumsum) {
this.index=index;
this.cumsum=cumsum;
indices=new ArrayList<Integer>();
}
public int compareTo(Pairr other) {
return Integer.compare(cumsum, other.cumsum);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | c51b8a21157251ae2d8668efa17bf02b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /*==========================================================================
* AUTHOR: RonWonWon
* CREATED: 29.10.2021 20:02:06
/*==========================================================================*/
import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
/*
in.ini();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
*/
long startTime = System.nanoTime();
int t = in.nextInt(), T = 1;
while(t-->0) {
int n = in.nextInt(), k = in.nextInt()+1;
int a[] = in.readArray(n);
long b[] = new long[n];
for(int i=0;i<n;i++) b[i] = (long)Math.pow(10L,a[i]);
long cur = 0, prev = 1, val = 0;
int ind = 0;
while(true){
if(ind+1==n){
long diff = k-val;
k -= diff;
out.print(diff);
while(ind>0){
ind--;
long next = b[ind+1]/b[ind]-1;
if(k-next>=0) out.print(next);
else{
int digits = 0;
long c = next;
while(c!=0){
c/=10; digits++;
}
char ch[] = new char[digits];
for(int i=digits-1;i>=0;i--){
ch[i] = (char)('0'+(k%10));
k/=10;
}
out.print(new String(ch));
}
}
break;
}
else{
long next = b[ind+1]/b[ind]-1;
if(val+next>=k){
long diff = k-val;
k -= diff;
out.print(diff);
while(ind>0){
ind--;
next = b[ind+1]/b[ind]-1;
if(k-next>=0) out.print(next);
else{
int digits = 0;
long c = next;
while(c!=0){
c/=10; digits++;
}
char ch[] = new char[digits];
for(int i=digits-1;i>=0;i--){
ch[i] = (char)('0'+(k%10));
k/=10;
}
out.print(new String(ch));
}
}
break;
}
prev = b[ind];
val += next;
}
ind++;
}
out.println();
//out.println("Case #"+T+": "+ans); T++;
}
/*
startTime = System.nanoTime() - startTime;
System.err.println("Time: "+(startTime/1000000));
*/
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static long ooo = Long.MAX_VALUE;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | dc8d64a69e1ec7de31da38fe7b89567b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class C_Banknotes {
static Scanner in=new Scanner();
static PrintWriter out=new PrintWriter( new OutputStreamWriter(System.out) );
static int n,k,testCases;
static long a[];
static void solve(){
++k;
long ans=0;
for(int i=0;i<n-1;i++){
if(k>0){
long x=(long)Math.pow(10, a[i+1]-a[i] )-1;
long value=Math.min(x,k);
ans+=(long)Math.pow(10,a[i])*value;
k-=value;
}
}
ans+=(long)Math.pow(10,a[n-1])*k;
out.println(ans);
out.flush();
}
public static void main(String[] args) throws IOException {
testCases=in.nextInt();
for(int t=0;t<testCases;t++){
n=in.nextInt();
k=in.nextInt();
a=new long[n];
for(int i=0;i<n;i++){
a[i]=in.nextLong();
}
solve();
}
in.close();
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static void merge(long a[],int left,int right,int mid){
int n1=mid-left+1,n2=right-mid;
long L[]=new long[n1];
long R[]=new long[n2];
for(int i=0;i<n1;i++){
L[i]=a[left+i];
}
for(int i=0;i<n2;i++){
R[i]=a[mid+1+i];
}
int i=0,j=0,k1=left;
while(i<n1 && j<n2){
if( L[i]<=R[j] ){
a[k1]=L[i];
i++;
}else{
a[k1]=R[j];
j++;
}
k1++;
}
while(i<n1){
a[k1]=L[i];
i++;
k1++;
}
while(j<n2){
a[k1]=R[j];
j++;
k1++;
}
}
static void sort(long a[],int left,int right){
if(left>=right){
return;
}
int mid=(left+right)/2;
sort(a,left,mid);
sort(a,mid+1,right);
merge(a,left,right,mid);
}
static class Scanner{
BufferedReader in;
StringTokenizer st;
public Scanner() {
in=new BufferedReader( new InputStreamReader(System.in) );
}
String next() throws IOException{
while(st==null || !st.hasMoreElements()){
st=new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong() throws IOException{
return Long.parseLong(next());
}
String nextLine() throws IOException{
return in.readLine();
}
char nextChar() throws IOException{
return next().charAt(0);
}
double nextDouble() throws IOException{
return Double.parseDouble(next());
}
float nextFloat() throws IOException{
return Float.parseFloat(next());
}
boolean nextBoolean() throws IOException{
return Boolean.parseBoolean(next());
}
void close() throws IOException{
in.close();
}
}
}
/*
4
3 13
0 1 2
2 777
0 4
3 255
0 1 3
10 1000000000
0 1 2 3 4 5 6 7 8 9
*/ | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | efca6a39a715fb9925771ea1aff7c14a | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Anubhav
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
CBanknotes solver = new CBanknotes();
solver.solve(1, in, out);
out.close();
}
static class CBanknotes {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long k = in.nextLong();
long ar[] = new long[n];
for (int i = 0; i < n; i++)
ar[i] = (long) Math.pow(10, in.nextLong());
long cp[] = new long[n];
for (int i = 0; i < n - 1; i++) {
long d = ar[i + 1] / ar[i];
cp[i] = d - 1;
}
int f = 0;
long ans = 0;
k++;
while (k > 0 && f < n - 1) {
long val = cp[f];
long add = val;
if (k < val)
add = k;
ans += add * ar[f];
k -= add;
f++;
}
if (k > 0)
ans += k * ar[n - 1];
out.println(ans);
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | c08b7af9699b071635e646ef1c0399c6 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.math.BigInteger;
import java.util.Scanner;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class cfContest1606 {
static long ch(long a, long[] val) {
long res = 0;
for (int i = val.length - 1; i >= 0; i--) {
res += (a / val[i]);
a -= (a / val[i]) * val[i];
}
return res;
}
public static void main(String args[]) throws IOException {
Reader scan = new Reader();
int t = scan.nextInt();
StringBuilder sb = new StringBuilder();
while (t-- > 0) {
int n = scan.nextInt();
int k = scan.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = scan.nextInt();
}
long[] val = new long[n];
for (int i = 0; i < n; i++) {
val[i] = (long) Math.pow(10, a[i]);
}
for (int i = 1; i < 19; i++) {
long p = (long) Math.pow(10, i) - 1;
long res = ch(p, val);
if (res > k) {
long r = p;
long pe = res - k;
long mx = 0;
for (int j = val.length - 1; j >= 0; j--) {
if (p / val[j] >= 1) {
mx = Math.max(mx, val[j]);
p -= (p / val[j]) * val[j];
}
}
System.out.println(r - mx * (pe - 1));
break;
}
}
}
}
}
class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg) {
return -ret;
}
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg) {
return -ret;
}
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg) {
return -ret;
}
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
}
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null) {
return;
}
din.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 68bc8fc56ccf80610478147d62d45f15 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
public class Main {
StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t,r,b,i,n,k,cnt,tmp;
long ans;
int[]p=new int[10];
int[]te= new int[10];
void run() throws IOException{
Scanner in=new Scanner(System.in);
te[0]=1;
for(i=1;i<10;i++)te[i]=te[i-1]*10;
t=in();
while(t-->0)
{
n=in();
k=in();
for(i=0;i<n;i++)
{
p[i]=in();
}
Arrays.sort(p,0,n);
cnt=0;
ans=0;
for(i=1;i<n;i++)
{
tmp=Math.min(k-cnt+1, te[p[i]]/te[p[i-1]]-1);
ans+=tmp*te[p[i-1]];
cnt+=tmp;
}
long tmp=k-cnt+1;
ans+=tmp*te[p[n-1]];
out.println(ans);
}
out.flush();
}
public static void main(String[]args) throws IOException {
new Main().run();
}
public int in() throws IOException {
in.nextToken();
return(int)in.nval;
}
public long inl() throws IOException {
in.nextToken();
return(long)in.nval;
}
public double ind() throws IOException {
in.nextToken();
return in.nval;
}
public String ins() throws IOException {
in.nextToken();
return in.sval;
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | f7e6eb1ab3bae54fd4506ef8aeb35d3f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
public class SolnC {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++) {
int n=sc.nextInt();
int k=sc.nextInt();
k++;
int[] a = new int[n];
for(int j=0;j<n;j++) {
a[j]=sc.nextInt();
}
long res = 0L;
for(int j=0;j<n-1;j++) {
if(k>0) {
long ans = (long) (Math.pow(10, a[j+1]-a[j])-1);
long best = Math.min(ans, k);
res=(long) Math.pow(10, a[j])*best+res;
k-=best;
}
}
if(k>0) {
res=res+(long) Math.pow(10, a[n-1])*k;
}
System.out.println(res);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4c917fdebaa055f808affec53806dd94 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
////***************************************************************************
/* public class E_Gardener_and_Tree implements Runnable{
public static void main(String[] args) throws Exception {
new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start();
}
public void run(){
WRITE YOUR CODE HERE!!!!
JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!!
}
}
*/
/////**************************************************************************
public class C_Banknotes{
public static void main(String[] args) {
FastScanner s= new FastScanner();
// PrintWriter out=new PrintWriter(System.out);
//end of program
//out.println(answer);
//out.close();
StringBuilder res = new StringBuilder();
int t=s.nextInt();
int p=0;
while(p<t){
int n=s.nextInt();
long k=s.nextLong();
int array[]= new int[n];
long value[]= new long[n];
for(int i=0;i<n;i++){
array[i]=s.nextInt();
value[i]=(long)Math.pow(10,array[i]);
}
ArrayList<Long> notes = new ArrayList<Long>();
for(int i=1;i<n;i++){
if(i==1){
notes.add((value[i]-1));
continue;
}
long num=value[i]-1;
long prev=value[i-1];
long hh=num/prev;
hh+=notes.get(notes.size()-1);
notes.add(hh);
}
int index=-1;
for(int i=0;i<notes.size();i++){
if(notes.get(i)>k){
index=i;
break;
}
}
if(index!=-1){
long number=value[index];
long ans=number-1;
long left=k;
if(index-1>=0){
left-=notes.get(index-1);
}
left++;
long yo=number*left;
ans+=yo;
res.append(ans+"\n");
}
else{
long number=value[value.length-1];
long ans=number-1;
index=value.length-1;
long left=k;
if(index-1>=0){
left-=notes.get(index-1);
}
left++;
long yo=number*left;
ans+=yo;
res.append(ans+"\n");
}
p++;
}
System.out.println(res);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 65ab2cde9d45b9c08389caaa48be59ae | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
static StringBuilder sb;
static long fact[];
static long mod = (long) (1e9 + 7);
static int[] arr = { 0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111 };
static void solve(int[] arr, int n, long k) {
long[] coins = new long[arr.length];
for (int i = 0; i < n; i++) {
coins[i] = p(10, arr[i]);
}
k++;
long s = 0;
for (int i = 0; i < n - 1; i++) {
long maxUsagePossible = Math.min((coins[i + 1] / coins[i]) - 1, k);
k -= maxUsagePossible;
s += maxUsagePossible * coins[i];
}
s += coins[n - 1] * k;
sb.append(s + "\n");
}
public static void main(String[] args) {
sb = new StringBuilder();
int test = i();
while (test-- > 0) {
int n = i();
long k = l();
int[] arr = readArray(n);
solve(arr, n, k);
}
out.printLine(sb);
out.flush();
out.close();
}
/*
* fact=new long[(int)1e6+10]; fact[0]=fact[1]=1; for(int i=2;i<fact.length;i++)
* { fact[i]=((long)(i%mod)1L(long)(fact[i-1]%mod))%mod; }
*/
// **************NCR%P******************
static long p(long x, long y)// POWER FXN //
{
if (y == 0)
return 1;
long res = 1;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % mod;
y--;
}
x = (x * x) % mod;
y = y / 2;
}
return res;
}
static long ncr(int n, int r) {
if (r > n)
return (long) 0;
long res = fact[n] % mod;
// System.out.println(res);
res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod;
res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod;
// System.out.println(res);
return res;
}
// **************END******************
// *************Disjoint set
// union*********//
// ***************PRIME FACTORIZE
// ***********************************//
static TreeMap<Integer, Integer> prime(long n) {
TreeMap<Integer, Integer> h = new TreeMap<>();
long num = n;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (n % i == 0) {
int nt = 0;
while (n % i == 0) {
n = n / i;
nt++;
}
h.put(i, nt);
}
}
if (n != 1)
h.put((int) n, 1);
return h;
}
// *****CLASS PAIR
// *************************************************
static class Pair implements Comparable<Pair> {
int x;
long y;
Pair(int x, long y) {
this.x = x;
this.y = y;
}
public int compareTo(Pair o) {
return (int) (this.y - o.y);
}
}
// *****CLASS PAIR
// ***************************************************
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static InputReader in = new InputReader(System.in);
static OutputWriter out = new OutputWriter(System.out);
public static long[] sortlong(long[] a2) {
int n = a2.length;
ArrayList<Long> l = new ArrayList<>();
for (long i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static int[] sortint(int[] a2) {
int n = a2.length;
ArrayList<Integer> l = new ArrayList<>();
for (int i : a2)
l.add(i);
Collections.sort(l);
for (int i = 0; i < l.size(); i++)
a2[i] = l.get(i);
return a2;
}
public static long pow(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 != 0) {
res = (res * x);// % modulus;
y--;
}
x = (x * x);// % modulus;
y = y / 2;
}
return res;
}
// GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public static long gcd(long x, long y) {
if (x == 0)
return y;
else
return gcd(y % x, x);
}
// ******LOWEST COMMON MULTIPLE
// *********************************************
public static long lcm(long x, long y) {
return (x * (y / gcd(x, y)));
}
// INPUT
// PATTERN********************************************************
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
public static int[] readArray(int n) {
int A[] = new int[n];
for (int i = 0; i < n; i++) {
A[i] = i();
}
return A;
}
public static long[] readArray(long n) {
long A[] = new long[(int) n];
for (int i = 0; i < n; i++) {
A[i] = l();
}
return A;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 959996419461afc60a6db7ddb5880ec2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /*==========================================================================
* AUTHOR: RonWonWon
* CREATED: 29.10.2021 20:02:06
/*==========================================================================*/
import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
/*
in.ini();
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
*/
long startTime = System.nanoTime();
int t = in.nextInt(), T = 1;
while(t-->0) {
int n = in.nextInt(), k = in.nextInt()+1;
int a[] = in.readArray(n);
long b[] = new long[n];
for(int i=0;i<n;i++) b[i] = (long)Math.pow(10L,a[i]);
long cur = 0, prev = 1, val = 0;
int ind = 0;
while(true){
if(ind+1==n){
long diff = k-val;
k -= diff;
out.print(diff);
while(ind>0){
ind--;
long next = b[ind+1]/b[ind]-1;
if(k-next>=0) out.print(next);
else{
int digits = 0;
long c = next;
while(c!=0){
c/=10; digits++;
}
char ch[] = new char[digits];
for(int i=digits-1;i>=0;i--){
ch[i] = (char)('0'+(k%10));
k/=10;
}
out.print(new String(ch));
}
}
break;
}
else{
long next = b[ind+1]/b[ind]-1;
if(val+next>=k){
long diff = k-val;
k -= diff;
out.print(diff);
while(ind>0){
ind--;
next = b[ind+1]/b[ind]-1;
if(k-next>=0) out.print(next);
else{
int digits = 0;
long c = next;
while(c!=0){
c/=10; digits++;
}
char ch[] = new char[digits];
for(int i=digits-1;i>=0;i--){
ch[i] = (char)('0'+(k%10));
k/=10;
}
out.print(new String(ch));
}
}
break;
}
prev = b[ind];
val += next;
}
ind++;
}
out.println();
//out.println("Case #"+T+": "+ans); T++;
}
/*
startTime = System.nanoTime() - startTime;
System.err.println("Time: "+(startTime/1000000));
*/
out.flush();
}
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static int oo = Integer.MAX_VALUE;
static long ooo = Long.MAX_VALUE;
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
void ini() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() {
while(!st.hasMoreTokens())
try { st = new StringTokenizer(br.readLine()); }
catch(IOException e) {}
return st.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readArrayL(int n) {
long a[] = new long[n];
for(int i=0;i<n;i++) a[i] = nextLong();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readArrayD(int n) {
double a[] = new double[n];
for(int i=0;i<n;i++) a[i] = nextDouble();
return a;
}
}
static final Random random = new Random();
static void ruffleSort(int[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n), temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSortL(long[] a){
int n = a.length;
for(int i=0;i<n;i++){
int j = random.nextInt(n);
long temp = a[j];
a[j] = a[i]; a[i] = temp;
}
Arrays.sort(a);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | a397f09818fcf9521f1308dfcebacbfd | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
long k = sc.nextInt();
int[] vals = new int[n];
long[] anss = new long[n];
for (int j = 0 ; j < n; j++) {
vals[j] = sc.nextInt();
}
for (int j = 0 ; j < n ; j++) {
if ( j == n - 1) {
anss[j] = k +1;
break ;
}
long temp = power(10,vals[j+1] - vals[j]) - 1;
if (temp > k) {
anss[j] = k + 1 ;
break ;
}
k = k - temp ;
anss[j] = temp ;
}
long ans = 0;
for (int j = 0 ; j < n ; j++) {
ans = ans + power(10,vals[j]) * anss[j] ;
}
System.out.println(ans);
}
}
static long power(long x, long y)
{
long res = 1;
x = x ;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) ;
y = y >> 1; // y = y/2
x = (x * x) ;
}
return res;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 8 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ab7eede2b10651038be732792f62010b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t,n,i,a;
long k,z,m;
t=sc.nextInt();
while (t>0)
{
n=sc.nextInt();
k=sc.nextInt(); k++;
int[] zm=new int[n];
long ans=0L;
for (i=0; i<n; i++)
{
a=sc.nextInt();
zm[i]=(int)Math.pow(10, a);
}
if (n==1 || k<10){System.out.println(k);}
else {
for (i=0; i<n-1; i++)
{;
z=zm[i]; m=zm[i+1];
if (k*z<m){ans+=k*z;k=0; i=n;}
else {k-=(m/z-1); ans+=(m/z-1)*z;};
}
if (k>0){ans+=k*zm[n-1];}
System.out.println(ans);
}
t--;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 12da65c037e202803ca0e5cf5ec3a26a | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t,n,i,a;
long k,z,m;
t=sc.nextInt();
while (t>0)
{
n=sc.nextInt();
k=sc.nextInt(); k++;
int[] zm=new int[n];
long ans=0L;
for (i=0; i<n; i++)
{
a=sc.nextInt();
zm[i]=(int)Math.pow(10, a);
}
if (n==1 || k<10){System.out.println(k);}
else {
for (i=0; i<n-1; i++)
{
//System.out.println("before ans"+ ans);
z=zm[i]; m=zm[i+1];
if (k*z<m){ans+=k*z;k=0; i=n;}
else {k-=(m/z-1); ans+=(m/z-1)*z;};
//System.out.println("afetr ans"+ans);
}
if (k>0){ans+=k*zm[n-1];}
System.out.println(ans);
}
t--;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 33b846b38532fabd8808c4d11dd6a7b2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main(String args[])
{
int t=1;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
while(t-- > 0)
{
int n=sc.nextInt();
long k=sc.nextLong();
k=k+1;
long [] arr=new long [n];
Map<Long,Long> m1=new HashMap<>();
for(int i=0;i<n;i++)
{
arr[i]=(long)Math.pow(10,sc.nextInt());
m1.put(arr[i],(long)0);
}
int i=0;
while(k>0)
{
if(i<n-1)
{
m1.put(arr[i],Math.min(k,arr[i+1]/arr[i]-1));
k=k-m1.get(arr[i]);
i++;
}
else{
break;
}
}
m1.put(arr[i],k);
long ans=0;
i=0;
while(i<n)
{
long n1=(long)arr[i]*(long)m1.get(arr[i]);
ans=ans+n1;
i++;
}
System.out.println(ans);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 341bc1e2c93dfa8c7e5a232a4776abf2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class snackDown3
{
public static class FastReader {
BufferedReader b;
StringTokenizer s;
public FastReader() {
b=new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(s==null ||!s.hasMoreElements()) {
try {
s=new StringTokenizer(b.readLine());
}
catch(IOException e) {
e.printStackTrace();
}
}
return s.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str="";
try {
str=b.readLine();
}
catch(IOException e) {
e.printStackTrace();
}
return str;
}
boolean hasNext() {
if (s != null && s.hasMoreTokens()) {
return true;
}
String tmp;
try {
b.mark(1000);
tmp = b.readLine();
if (tmp == null) {
return false;
}
b.reset();
} catch (IOException e) {
return false;
}
return true;
}
}
public static void main (String[] args) throws Exception
{
// your code goes here
FastReader sc=new FastReader();
int t=sc.nextInt();
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
while(t--!=0) {
int n=sc.nextInt();
long k=sc.nextLong();
int a[]=new int[n];
long start=0;
// int p=(int)Math.pow(10, 9);
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
}
k++;
int cnt=1;
for(int i=0;i<n-1;i++) {
long num=(long)Math.pow(10,a[i]);
int diff=a[i+1]-a[i];
long numm=((long)Math.pow(10, diff))-1;
if(k>numm) {
k-=numm;
start+=(numm*num);
}
else if(k<=numm) {
start=(k*num)+start;
k=0;
break;
}
}
if(k>0) {
long num=((long)Math.pow(10, a[n-1]));
start=((k)*num)+start;
}
log.write(start+"");
log.write("\n");
log.flush();
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 3c92637d231d163d3269873abf7cffff | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | //package watermelon;
import java.util.Scanner;
public class BankNotes {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long test = scan.nextInt();
int num;
long k;
int[] denomination;
for (int t = 0; t < test; t++) {
num = scan.nextInt();
k = scan.nextInt() + 1;
denomination = new int[num];
for (int i = 0; i < num; i++) {
denomination[i] = scan.nextInt();
}
long min = 0;
int nextD = 1;
long gap;
while(nextD < denomination.length) {
gap = (long) (Math.pow(10, denomination[nextD] - denomination[nextD - 1]) - 1);
if(k > gap) {
min += gap * Math.pow(10, denomination[nextD - 1]);
nextD++;
k -= gap;
}else {
min += k * Math.pow(10, denomination[nextD - 1]);
k = 0;
nextD++;
break;
}
}
//if k != 0 that means nextD == denomination.length
if(k != 0) {
min += (long) ( k * Math.pow(10, denomination[nextD - 1]));
}
System.out.println(min);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 6aa185b4583bb5c0beb1eb504dcb170d | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | //package watermelon;
import java.util.Scanner;
public class BankNotes {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long test = scan.nextInt();
int num;
int k;
long[] denomination;
for (int t = 0; t < test; t++) {
num = scan.nextInt();
k = scan.nextInt() + 1;
denomination = new long[num];
for (int i = 0; i < num; i++) {
denomination[i] = (long) Math.pow(10, scan.nextInt());
}
long min = 0;
int nextD = 1;
long gap;
while(nextD < denomination.length) {
gap = (denomination[nextD]/denomination[nextD - 1] - 1);
if(k - gap > 0) {
min += gap * denomination[nextD - 1];
nextD++;
k -= gap;
}else {
min += k * denomination[nextD - 1];
k = 0;
nextD++;
break;
}
}
min += k * denomination[nextD - 1];
System.out.println(min);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | a5a6991cfbc4e52102b4636597b7b045 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | // Generated by Code Flattener.
// https://plugins.jetbrains.com/plugin/9979-idea-code-flattener
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
Solution solution = new ASolution();
boolean local = System.getProperty("ONLINE_JUDGE") == null && !solution.isInteractive();
String input = local ? "input.txt" : null;
solution.in = new MyScanner(input);
solution.out = MyWriter.of(null);
solution.bm = new Benchmark();
solution.al = new Algorithm();
solution.run();
solution.close();
}
private abstract static class Solution {
public MyScanner in;
public MyWriter out;
public Benchmark bm;
public Algorithm al;
public void init() {
}
public abstract void solve();
protected boolean isMultiTest() {
return true;
}
public void run() {
init();
if (isMultiTest()) {
int t = in.nextInt();
for (int i = 0; i < t; i++) {
solve();
}
} else {
solve();
}
}
public void close() {
out.close();
}
public boolean isInteractive() {
return false;
}
}
private static class ASolution extends Solution {
BigInteger need(BigInteger x, BigInteger[] b) {
BigInteger count = BigInteger.ZERO;
for (BigInteger l : b) {
BigInteger tmp = x.divide(l);
x = x.subtract(l.multiply(tmp));
count = count.add(tmp);
}
return count;
}
public void solve() {
int n = in.nextInt();
BigInteger k = BigInteger.valueOf(in.nextInt());
int[] a = in.nextInts(n);
BigInteger[] b = new BigInteger[n];
for (int i = 0; i < n; i++) {
b[n - 1 - i] = BigInteger.TEN.pow(a[i]);
}
BigInteger ans = BigInteger.ZERO;
for (int j = 20; j >= 0; j--) {
BigInteger x = BigInteger.TEN.pow(j);
BigInteger count1 = need(x.subtract(BigInteger.ONE), b);
BigInteger count2 = need(x, b);
ans = ans.multiply(BigInteger.TEN);
if (count1.compareTo(k) <= 0) {
BigInteger tmp = k.subtract(count1);
BigInteger tmp2 = tmp.divide(count2).add(BigInteger.ONE);
ans = ans.add(tmp2);
k = k.subtract(tmp2.multiply(count2));
}
}
out.println(ans);
}
}
private static class MyScanner {
private final BufferedReader br;
private StringTokenizer st;
public MyScanner(String fileName) {
if (fileName != null) {
try {
File file = new File(getClass().getClassLoader().getResource(fileName).getFile());
br = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
} else {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
public String next() {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public int[] nextInts(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public String nextLine() {
try {
String line = br.readLine();
if (line == null) {
throw new RuntimeException("empty line");
}
st = null;
return line;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
private static class Benchmark {
}
private static class Algorithm {
}
private static class MyWriter extends PrintWriter {
public static MyWriter of(String fileName) {
if (fileName != null) {
try {
return new MyWriter(new FileWriter(fileName));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
return new MyWriter(new BufferedOutputStream(System.out));
}
}
public MyWriter(Writer writer) {
super(writer);
}
public MyWriter(OutputStream out) {
super(out);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 45e673dfc4ebae42085c95523af10f4f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class C_1606 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int[] pow = new int[10];
pow[0] = 1;
for(int i = 1; i < 10; i++)
pow[i] = pow[i - 1] * 10;
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt(), k = sc.nextInt();
int[] array = sc.nextIntArray(n);
for(int i = 0; i < n; i++)
array[i] = pow[array[i]];
long ans = Long.MAX_VALUE;
for(int i = 0; i < n; i++) {
long remK = k;
long val = 0;
for(int j = 0; j <= i; j++) {
long max = 1l * (((j == n - 1) ? (long)7e18 : array[j + 1]) / array[j]) - 1;
long min = Math.min(remK, max);
remK -= min;
if(remK == 0 && min == max) {
val += 1l * min * array[j];
} else if(remK == 0) {
val += 1l * (min + 1) * array[j];
break;
} else {
val += 1l * min * array[j];
}
}
if(val < 1l * (i == n - 1 ? (long)7e18 : array[i + 1]) - 1) {
ans = Math.min(ans, val);
}
}
pw.println(ans);
}
pw.flush();
}
public static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public Scanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public int[] nextIntArray(int n) throws IOException {
int[] array = new int[n];
for (int i = 0; i < n; i++)
array[i] = nextInt();
return array;
}
public Integer[] nextIntegerArray(int n) throws IOException {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++)
array[i] = new Integer(nextInt());
return array;
}
public long[] nextLongArray(int n) throws IOException {
long[] array = new long[n];
for (int i = 0; i < n; i++)
array[i] = nextLong();
return array;
}
public double[] nextDoubleArray(int n) throws IOException {
double[] array = new double[n];
for (int i = 0; i < n; i++)
array[i] = nextDouble();
return array;
}
public static int[] shuffle(int[] a) {
int n = a.length;
Random rand = new Random();
for (int i = 0; i < n; i++) {
int tmpIdx = rand.nextInt(n);
int tmp = a[i];
a[i] = a[tmpIdx];
a[tmpIdx] = tmp;
}
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 8b436299a110b8035dfbfdaab6badfa4 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /***** ---> :) Vijender Srivastava (: <--- *****/
import java.util.Queue;
import java.util.LinkedList;
import java.util.*;
import java.lang.*;
// import java.lang.reflect.Array;
import java.io.*;
public class Main
{
static FastReader sc =new FastReader();
static PrintWriter out=new PrintWriter(System.out);
static long mod=998244353;
static StringBuilder sb = new StringBuilder();
/* start */
public static void main(String [] args)
{
// int testcases = 1;
int testcases = i();
while(testcases-->0)
{
solve();
}
out.flush();
out.close();
}
static void solve()
{
int n = i();
long k = l()+1;
int a[] = input(n);
long pow[] = new long[n];
for(int i=0;i<n;i++)
{
pow[i] = power(10, a[i]);
}
long ans = 0;
for(int i=0;i<n;i++)
{
if(i!=n-1)
{
ans+=(min((pow[i+1]/pow[i])-1,k)*pow[i]);
k-=min((pow[i+1]/pow[i])-1,k);
} else {
ans+=(pow[i]*(k));
k=0;
}
if(k<=0) break;
}
pl(ans);
}
/* end */
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static void p(Object o)
{
out.print(o);
}
static void pl(Object o)
{
out.println(o);
}
static int i() {
return sc.nextInt();
}
static String s() {
return sc.next();
}
static long l() {
return sc.nextLong();
}
static char[] inputC()
{
String s = sc.nextLine();
return s.toCharArray();
}
static int[] input(int n) {
int A[]=new int[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextInt();
}
return A;
}
static long[] inputL(int n) {
long A[]=new long[n];
for(int i=0;i<n;i++) {
A[i]=sc.nextLong();
}
return A;
}
static long[] putL(long a[]) {
long A[]=new long[a.length];
for(int i=0;i<a.length;i++) {
A[i]=a[i];
}
return A;
}
static String[] inputS(int n) {
String A[]=new String[n];
for(int i=0;i<n;i++) {
A[i]=sc.next();
}
return A;
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static String reverse(String s) {
StringBuffer p=new StringBuffer(s);
p.reverse();
return p.toString();
}
static int min(int a,int b) {
return Math.min(a, b);
}
static int min(int a,int b,int c) {
return Math.min(a, Math.min(b, c));
}
static int min(int a,int b,int c,int d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static int max(int a,int b) {
return Math.max(a, b);
}
static int max(int a,int b,int c) {
return Math.max(a, Math.max(b, c));
}
static int max(int a,int b,int c,int d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long min(long a,long b) {
return Math.min(a, b);
}
static long min(long a,long b,long c) {
return Math.min(a, Math.min(b, c));
}
static long min(long a,long b,long c,long d) {
return Math.min(a, Math.min(b, Math.min(c, d)));
}
static long max(long a,long b) {
return Math.max(a, b);
}
static long max(long a,long b,long c) {
return Math.max(a, Math.max(b, c));
}
static long max(long a,long b,long c,long d) {
return Math.max(a, Math.max(b, Math.max(c, d)));
}
static long sum(int A[]) {
long sum=0;
for(int i : A) {
sum+=i;
}
return sum;
}
static long sum(long A[]) {
long sum=0;
for(long i : A) {
sum+=i;
}
return sum;
}
static void print(int A[]) {
for(int i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(long A[]) {
for(long i : A) {
System.out.print(i+" ");
}
System.out.println();
}
static long mod(long x) {
return ((x%mod + mod)%mod);
}
static long power(long x, long y)
{
if(y==0)
return 1;
if(x==0)
return 0;
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) ;
y = y >> 1;
x = (x * x);
}
return res;
}
static boolean prime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean prime(long n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
double sq=Math.sqrt(n);
for (int i = 5; i <= sq; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static long[] sort(long a[]) {
ArrayList<Long> arr = new ArrayList<>();
for(long i : a) {
arr.add(i);
}
Collections.sort(arr);
for(int i = 0; i < arr.size(); i++) {
a[i] = arr.get(i);
}
return a;
}
static int[] sort(int a[])
{
ArrayList<Integer> arr = new ArrayList<>();
for(Integer i : a) {
arr.add(i);
}
Collections.sort(arr);
for(int i = 0; i < arr.size(); i++) {
a[i] = arr.get(i);
}
return a;
}
//pair class
private static class Pair implements Comparable<Pair> {
int first, second;
public Pair(int f, int s) {
first = f;
second = s;
}
@Override
public int compareTo(Pair p) {
if (first > p.first)
return 1;
else if (first < p.first)
return -1;
else {
if (second < p.second)
return 1;
else if (second > p.second)
return -1;
else
return 0;
}
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 46c8c1b46db6e634edf32d3a18e9107b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Banknotes{
public static void main(String args[])throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder result = new StringBuilder();
int testCases = Integer.parseInt(br.readLine());
StringTokenizer str;
while(testCases-- > 0){
str = new StringTokenizer(br.readLine());
int n = Integer.parseInt(str.nextToken());
long k = Long.parseLong(str.nextToken());
int nums[] = new int[n];
int denomination[] = new int[n];
str = new StringTokenizer(br.readLine());
for(int i = 0; i < n; i++){
nums[i] = Integer.parseInt(str.nextToken());
}
long answer = 0;
if(n == 1 || k < 9){
answer = k + 1;
}else {
k++;
for(int i = 0; i < n -1; i++){
if(k > 0){
long x = (long)Math.pow(10, nums[i + 1] - nums[i]) - 1;
long y = Math.min(x, k);
answer += Math.pow(10, nums[i]) * y;
k -= y;
}else{
break;
}
}
if(k > 0){
answer += (long)Math.pow(10, nums[n - 1]) * k;
}
}
result.append(answer + "\n");
}
System.out.println(result);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 9fdbb9b4dcc26331c1c53333264c3e0b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.awt.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
// System.out.println(Long.MAX_VALUE);
int t = Reader.nextInt();
while ( t > 0 ){
int n = Reader.nextInt();
long k =Reader.nextLong()+1;
long[] array = new long[n];
int i = 0;
while ( i < n){
array[i] = (long)Math.pow(10,Reader.nextLong());
i++;
}
long ans = 0;
i = 0;
while ( i < n && k != 0){
if ( i == n-1){
ans+= (k*array[i]);
k=0;
}
else{
long allowed = (array[i+1]/array[i])-1;
long min = min(allowed,k);
k-=min;
ans+= min*array[i];
}
i++;
}
//System.out.println(ans);
output.write(ans+"\n");
t--;
}
output.flush();
}
private static long helper(long[] array,int n,long k,long num){
System.out.println(num);
int i = n-1;
long counts = 0;
while (num!= 0){
counts+=(num/array[i]);
num = num%array[i];
i--;
}
if (counts> k){
return -1;
}
else{
return 1;
}
}
private static int bs(int low,int high,ArrayList<Integer> array,int find){
if ( low <= high ){
int mid = low + (high-low)/2;
if ( array.get(mid) > find){
high = mid -1;
return bs(low,high,array,find);
}
else if ( array.get(mid) < find){
low = mid+1;
return bs(low,high,array,find);
}
return mid;
}
return -1;
}
private static long max(long a, long b) {
return Math.max(a,b);
}
private static long min(long a,long b){
return Math.min(a,b);
}
public static long modularExponentiation(long a,long b,long mod){
if ( b == 1){
return a;
}
else{
long ans = modularExponentiation(a,b/2,mod)%mod;
if ( b%2 == 1){
return (a*((ans*ans)%mod))%mod;
}
return ((ans*ans)%mod);
}
}
public static long sum(long n){
return (n*(n+1))/2;
}
public static long abs(long a){
return a < 0 ? (-1*a) : a;
}
public static long gcd(long a,long b){
if ( a == 0){
return b;
}
else{
return gcd(b%a,a);
}
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next());
}
}
/*
class NComparator implements Comparator<Node>{
@Override
public int compare(Node o1, Node o2) {
if ( o2.position > o1.position){
return 1;
}
else if ( o2.position < o1.position){
return -1;
}
else{
if ( o2.time < o1.time){
return 1;
}
else if ( o2.time > o2.time){
return -1;
}
else{
return 0;
}
}
}
}
*/
class DComparator implements Comparator<Long>{
@Override
public int compare(Long o1, Long o2) {
if ( o2 > o1){
return 1;
}
else if ( o2 < o1){
return -1;
}
else{
return 0;
}
}
}
class Node{
long position;
long speed;
Node(long p,long s){
position = p;
speed = s;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | fbf566274cfd10fda04493289e0d7874 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
//Banknotes
public class Banknotes {
public static void main(String[] args) {
Banknotes.solution();
}
public static void solution() {
Scanner scanner = new Scanner(System.in);
int numCases = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < numCases; i++) {
String[] tokens = scanner.nextLine().split(" ");
int k = Integer.parseInt(tokens[1]) + 1;
int[] denominations = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
long num = 0;
for (int j = 0; j < denominations.length; j++) {
long currDenom = (int) Math.pow(10, denominations[j]);
long nextDenom = j + 1 < denominations.length ? (int) Math.pow(10, denominations[j + 1]) : -1;
long next = j + 1 < denominations.length ? (nextDenom / currDenom) - 1 : Integer.MAX_VALUE;
long used = Math.min(k, next);
num += (currDenom * used);
k -= used;
}
System.out.println(num);
}
}
}
//Learnings: how to minimize f(s)?
// 1) select the max number of 1's, then the max number of 10's, then the max number of 100's, etc
// 2) The most 1's you can select is Math.min(kLeft, 10/1 - 1), 10's --> Math.min(kLeft, 100/10 - 1), and so on | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d7dd66220f2c03452d506b94a28f06e9 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
//Banknotes
public class Banknotes {
public static void main(String[] args) {
Banknotes.solution();
}
public static void solution() {
Scanner scanner = new Scanner(System.in);
int numCases = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < numCases; i++) {
String[] tokens = scanner.nextLine().split(" ");
int k = Integer.parseInt(tokens[1]) + 1;
int[] denominations = Arrays.stream(scanner.nextLine().split(" ")).collect(Collectors.toList()).stream().mapToInt(Integer::parseInt).toArray();
long num = 0;
for (int j = 0; j < denominations.length; j++) {
long currDenom = (int) Math.pow(10, denominations[j]);
long nextDenom = j + 1 < denominations.length ? (int) Math.pow(10, denominations[j + 1]) : -1;
long next = j + 1 < denominations.length ? (nextDenom / currDenom) - 1 : Integer.MAX_VALUE;
long used = Math.min(k, next);
num += (currDenom * used);
k -= used;
}
System.out.println(num);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 13b3bea4a513776ce5c4ddc431df85c3 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class a {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int t = in.nextInt();
while(t-- > 0) {
int n,k;
n = in.nextInt();
k = in.nextInt();
long ans=0;
int[] a = new int[n];
for(int i=0;i<n;i++) {
a[i] = in.nextInt();
}
int ij=n-1;
for(int i=0;i<n-1;i++) {
if(k==0)break;
for(int j=0;j<a[i+1]-a[i];j++) {
// if(i==0)out.println("LNA");
if(k==0)break;
if(k>Math.pow(10,j)*9) {
ans+=(Math.pow(10,j)*9)*Math.pow(10, a[i]);
k-=Math.pow(10,j)*9;
// out.println(ans+ " I "+i +" " + j+ " " +k);
}
else {
ans+=k*Math.pow(10, a[i]);
k=0;
// out.println(ans+ " II "+i);
}
}
ij=i;
// out.println(ans+ " "+i);
}
// out.println(ans+ " "+k);
if(k>0)ij=n-1;
ans=ans+(long)(Math.pow(10, a[n-1])*k);
if(ij<n-1 && ans<(long)(Math.pow(10, a[ij+1])) && ans+(long)(Math.pow(10, a[ij]))>=Math.pow(10, a[ij+1])){
ans = ans + (long)(Math.pow(10, a[ij+1]));
}
else
ans = ans + (long)(Math.pow(10, a[ij]));
// if(ij>-1)ans=ans+(long)(Math.pow(10, a[ij]));
// else if(ij==-1) {
//
// }
out.println(ans);
}
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | dc6702dd3db2ae1cacb8cce81f42811f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.awt.Point;
public class Main{
static int mod = (int) (Math.pow(10, 9)+7);
static final int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
static final int[] dx8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
static final int[] dx9 = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy9 = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
static final int inf = Integer.MAX_VALUE / 2;
static final long infL = Long.MAX_VALUE / 3;
static final double infD = Double.MAX_VALUE / 3;
static final double eps = 1e-10;
static final double pi = Math.PI;
static List<Integer> primeNumbers = new ArrayList<>();
public static void main(String[] args) throws IOException{
MyScanner sc = new MyScanner();
//changes in this line of code
out = new PrintWriter(new BufferedOutputStream(System.out));
// out = new PrintWriter(new BufferedWriter(new FileWriter("output.out")));
//will this work on codeforces?
int test = sc.nextInt();
while(test -- > 0){
int n = sc.nextInt();
long k = sc.nextLong();
long[] arr = new long[n];
for(int i= 0; i < n; i++) arr[i] = (long)Math.pow(10, sc.nextLong());
long answer = 0;
for(int i = 0; i < n; i++){
if(i == n-1){
//do whatever you can
answer += ((long)(k+1)) * arr[i];
}else{
long currMax = arr[i+1]/arr[i] - 1L;
if(k >= currMax){
answer += currMax * arr[i];
k -= currMax;
}else{
answer += (k+1) * arr[i];
break;
}
}
}
out.println(answer);
}
out.close();
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
//fast java implementation for sure
public static class Graph{
public int V;
public ArrayList<ArrayList<Integer>> edges;
Graph(int V){
this.V = V;
edges = new ArrayList<>(V+1);
for(int i= 0; i <= V; i++){
edges.add(new ArrayList<>());
}
}
///single sided this for sure
public void addEdge(int from , int to){
edges.get(from).add(to);
}
}
public static class DisjointUnionSets {
int[] rank, parent;
int n;
// Constructor
public DisjointUnionSets(int n)
{
rank = new int[n];
parent = new int[n];
this.n = n;
makeSet();
}
// Creates n sets with single item in each
void makeSet()
{
for (int i = 0; i < n; i++) {
// Initially, all elements are in
// their own set.
parent[i] = i;
}
}
// Returns representative of x's set
int find(int x)
{
// Finds the representative of the set
// that x is an element of
if (parent[x] != x) {
// if x is not the parent of itself
// Then x is not the representative of
// his set,
parent[x] = find(parent[x]);
// so we recursively call Find on its parent
// and move i's node directly under the
// representative of this set
}
return parent[x];
}
// Unites the set that includes x and the set
// that includes x
void union(int x, int y)
{
// Find representatives of two sets
int xRoot = find(x), yRoot = find(y);
// Elements are in the same set, no need
// to unite anything.
if (xRoot == yRoot)
return;
// If x's rank is less than y's rank
if (rank[xRoot] < rank[yRoot])
// Then move x under y so that depth
// of tree remains less
parent[xRoot] = yRoot;
// Else if y's rank is less than x's rank
else if (rank[yRoot] < rank[xRoot])
// Then move y under x so that depth of
// tree remains less
parent[yRoot] = xRoot;
else // if ranks are the same
{
// Then move y under x (doesn't matter
// which one goes where)
parent[yRoot] = xRoot;
// And increment the result tree's
// rank by 1
rank[xRoot] = rank[xRoot] + 1;
}
}
}
//with mod
public static long power(long x, long y)
{
long res = 1L; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0){
x %= mod;
res %= mod;
res = (res * x)%mod;
}
// y must be even now
y = y >> 1; // y = y/2
x%= mod;
x = (x * x)%mod; // Change x to x^2
}
// 550193677
return res%mod;
}
//without mod
public static long power2(long x, long y)
{
long res = 1L; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0){
res = (res * x);
}
// y must be even now
y = y >> 1; // y = y/
x = (x * x);
}
// 550193677
return res;
}
public static class segmentTree{
public long[] arr;
public long[] tree;
public long[] lazy;
segmentTree(long[] array){
int n = array.length;
arr = new long[n];
for(int i= 0; i < n; i++) arr[i] = array[i];
tree = new long[4*n + 1];
lazy = new long[4*n + 1];
}
public void build(int[]arr, int s, int e, int[] tree, int index){
if(s == e){
tree[index] = arr[s];
return;
}
//otherwise divide in two parts and fill both sides simply
int mid = (s+e)/2;
build(arr, s, mid, tree, 2*index);
build(arr, mid+1, e, tree, 2*index+1);
//who will build the current position dude
tree[index] = Math.min(tree[2*index], tree[2*index+1]);
}
public int query(int sr, int er, int sc, int ec, int index, int[] tree){
if(lazy[index] != 0){
tree[index] += lazy[index];
if(sc != ec){
lazy[2*index+1] += lazy[index];
lazy[2*index] += lazy[index];
}
lazy[index] = 0;
}
//no overlap
if(sr > ec || sc > er) return Integer.MAX_VALUE;
//found the index baby
if(sr <= sc && ec <= er) return tree[index];
//finding the index on both sides hehehehhe
int mid = (sc + ec)/2;
int left = query(sr, er, sc, mid, 2*index, tree);
int right = query(sr, er, mid+1, ec, 2*index + 1, tree);
return Integer.min(left, right);
}
//now we will do point update implementation
//it should be simple then we expected for sure
public void update(int index, int indexr, int increment, int[] tree, int s, int e){
if(lazy[index] != 0){
tree[index] += lazy[index];
if(s != e){
lazy[2*index+1] = lazy[index];
lazy[2*index] = lazy[index];
}
lazy[index] = 0;
}
//no overlap
if(indexr < s || indexr > e) return;
//found the required index
if(s == e){
tree[index] += increment;
return;
}
//search for the index on both sides
int mid = (s+e)/2;
update(2*index, indexr, increment, tree, s, mid);
update(2*index+1, indexr, increment, tree, mid+1, e);
//now update the current range simply
tree[index] = Math.min(tree[2*index+1], tree[2*index]);
}
public void rangeUpdate(int[] tree , int index, int s, int e, int sr, int er, int increment){
//if not at all in the same range
if(e < sr || er < s) return;
//complete then also move forward
if(s == e){
tree[index] += increment;
return;
}
//otherwise move in both subparts
int mid = (s+e)/2;
rangeUpdate(tree, 2*index, s, mid, sr, er, increment);
rangeUpdate(tree, 2*index + 1, mid+1, e, sr, er, increment);
//update current range too na
//i always forget this step for some reasons hehehe, idiot
tree[index] = Math.min(tree[2*index], tree[2*index + 1]);
}
public void rangeUpdateLazy(int[] tree, int index, int s, int e, int sr, int er, int increment){
//update lazy values
//resolve lazy value before going down
if(lazy[index] != 0){
tree[index] += lazy[index];
if(s != e){
lazy[2*index+1] += lazy[index];
lazy[2*index] += lazy[index];
}
lazy[index] = 0;
}
//no overlap case
if(sr > e || s > er) return;
//complete overlap
if(sr <= s && er >= e){
tree[index] += increment;
if(s != e){
lazy[2*index+1] += increment;
lazy[2*index] += increment;
}
return;
}
//otherwise go on both left and right side and do your shit
int mid = (s + e)/2;
rangeUpdateLazy(tree, 2*index, s, mid, sr, er, increment);
rangeUpdateLazy(tree, 2*index + 1, mid+1, e, sr, er, increment);
tree[index] = Math.min(tree[2*index+1], tree[2*index]);
return;
}
}
//prime sieve
public static void primeSieve(int n){
BitSet bitset = new BitSet(n+1);
for(long i = 0; i < n ; i++){
if (i == 0 || i == 1) {
bitset.set((int) i);
continue;
}
if(bitset.get((int) i)) continue;
primeNumbers.add((int)i);
for(long j = i; j <= n ; j+= i)
bitset.set((int)j);
}
}
//number of divisors
public static int countDivisors(long number){
if(number == 1) return 1;
List<Integer> primeFactors = new ArrayList<>();
int index = 0;
long curr = primeNumbers.get(index);
while(curr * curr <= number){
while(number % curr == 0){
number = number/curr;
primeFactors.add((int) curr);
}
index++;
curr = primeNumbers.get(index);
}
if(number != 1) primeFactors.add((int) number);
int current = primeFactors.get(0);
int totalDivisors = 1;
int currentCount = 2;
for (int i = 1; i < primeFactors.size(); i++) {
if (primeFactors.get(i) == current) {
currentCount++;
} else {
totalDivisors *= currentCount;
currentCount = 2;
current = primeFactors.get(i);
}
}
totalDivisors *= currentCount;
return totalDivisors;
}
//now adding next permutation function to java hehe
public static boolean next_permutation(int[] p) {
for (int a = p.length - 2; a >= 0; --a)
if (p[a] < p[a + 1])
for (int b = p.length - 1;; --b)
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
return false;
}
//finding the value of NCR in O(RlogN) time and O(1) space
public static long getNcR(int n, int r)
{
long p = 1, k = 1;
if (n - r < r) r = n - r;
if (r != 0) {
while (r > 0) {
p *= n;
k *= r;
long m = __gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
}
else {
p = 1;
}
return p;
}
public static void sort(long[] a) {
ArrayList<Long> l=new ArrayList<>();
for (long i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//for ncr calculator
public static long __gcd(long n1, long n2)
{
long gcd = 1;
for (int i = 1; i <= n1 && i <= n2; ++i) {
// Checks if i is factor of both integers
if (n1 % i == 0 && n2 % i == 0) {
gcd = i;
}
}
return gcd;
}
//is vowel function
public static boolean isVowel(char c)
{
return (c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U');
}
//two add two big numbers with some mod
public static int add(int a, int b) {
a+=b;
if (a>=mod) return a-mod;
return a;
}
//two sub two numbers
public static int sub(int a, int b) {
a-=b;
if (a<0) a+=mod;
else if (a>=mod) a-=mod;
return a;
}
//to sort the array with better method
public static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//for calculating binomialCoeff
public static int binomialCoeff(int n, int k)
{
int C[] = new int[k + 1];
// nC0 is 1
C[0] = 1;
for (int i = 1; i <= n; i++) {
// Compute next row of pascal
// triangle using the previous row
for (int j = Math.min(i, k); j > 0; j--)
C[j] = C[j] + C[j - 1];
}
return C[k];
}
//Pair with int int
public static class Pair{
public int a;
public int b;
Pair(int a , int b){
this.a = a;
this.b = b;
}
@Override
public String toString(){
return a + " -> " + b;
}
}
//Triplet with int int int
public static class Triplet{
public int a;
public int b;
public int c;
Triplet(int a , int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
@Override
public String toString(){
return a + " -> " + b;
}
}
//Shortcut function
public static long lcm(long a , long b){
return a * (b/gcd(a,b));
}
//let's make one for calculating lcm basically
public static int lcm(int a , int b){
return (a * b)/gcd(a,b);
}
//int version for gcd
public static int gcd(int a, int b){
if(b == 0)
return a;
return gcd(b , a%b);
}
//long version for gcd
public static long gcd(long a, long b){
if(b == 0)
return a;
return gcd(b , a%b);
}
//swapping two elements in an array
public static void swap(int[] arr, int left , int right){
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
//
//for char array
public static void swap(char[] arr, int left , int right){
char temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
//reversing an array
public static void reverse(int[] arr){
int left = 0;
int right = arr.length-1;
while(left <= right){
swap(arr, left,right);
left++;
right--;
}
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
// public MyScanner() throws FileNotFoundException {
// br = new BufferedReader(new FileReader("input.in"));
// }
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 0c91e7cd03e5de15c31590e48448967f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | // हर हर महादेव
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.DecimalFormat;
public final class Solution {
static int inf = Integer.MAX_VALUE;
static long mod = 1000000000 + 7;
static void ne(Reader sc, BufferedWriter op) throws Exception {
int n= sc.nextInt();
long k=sc.nextLong();
long[] arr= new long[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextLong();
}
long curr=0;
boolean ff=false;
// long notes=0;
for(int i=0;i<n-1;i++){
long diff=(no(arr[i+1])/no(arr[i]))-1;
if(diff>k){
k++;
curr+=k*no(arr[i]);
k=0;
break;
}else{
curr+=diff*no(arr[i]);
k-=diff;
if(k==0){
curr+=no(arr[i+1]);
break;
}
}
}
if(k>0){
k++;
curr+=k*no(arr[n-1]);
}
op.write(curr+"\n");
}
static long no(long num){
long ans=1L;
while(num-->0){
ans*=10L;
}
return ans;
}
static long gcd(long a, long b){
if(a==0) return b;
return gcd(b%a,a);
}
// static int lcm(int a, int b){
// return (a*b)/gcd(a,b);
// }
public static void main(String[] args) throws Exception {
BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out));
// Reader sc = new Reader();
Reader sc= new Reader();
int t = sc.nextInt();
while (t-->0){ne(sc, op);}
// ne(sc,op);
op.flush();
}
static void print(Object o) {
System.out.println(String.valueOf(o));
}
static int[] toIntArr(String s){
int[] val= new int[s.length()];
for(int i=0;i<s.length();i++){
val[i]=s.charAt(i)-'a';
}
return val;
}
static void sort(int[] arr){
ArrayList<Integer> list= new ArrayList<>();
for(int i=0;i<arr.length;i++){
list.add(arr[i]);
}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i]=list.get(i);
}
}
static void sort(long[] arr){
ArrayList<Long> list= new ArrayList<>();
for(int i=0;i<arr.length;i++){
list.add(arr[i]);
}
Collections.sort(list);
for(int i=0;i<arr.length;i++){
arr[i]=list.get(i);
}
}
}
// return -1 to put no ahed in array
class pair {
int xx;
int yy;
pair(int xx, int yy ) {
this.xx = xx;
this.yy = yy;
}
}
class sortY implements Comparator<pair> {
public int compare(pair p1, pair p2) {
if (p1.yy > p2.yy) {
return -1;
} else if (p1.yy == p2.yy) {
if (p1.xx > p2.xx) {
return 1;
} else if (p1.xx < p2.xx) {
return -1;
}
return 0;
}
return 1;
}
}
class sortX implements Comparator<pair> {
public int compare(pair p1, pair p2) {
if (p1.xx > p2.xx) {
return 1;
} else if (p1.xx == p2.xx) {
if (p1.yy > p2.yy) {
return 1;
} else if (p1.yy < p2.yy) {
return -1;
}
return 0;
}
return -1;
}
}
class debug {
static void print1d(long[] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
static void print1d(int[] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
static void print1d(boolean[] arr) {
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.println(i + "= " + arr[i] + " ");
}
}
static void print2d(int[][] arr) {
System.out.println();
int n = arr.length;
int n2 = arr[0].length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n2; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
static void print2d(long[][] arr) {
System.out.println();
int n = arr.length;
int n2 = arr[0].length;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n2; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
static void printPair(ArrayList<pair> list) {
if(list.size()==0){
System.out.println("empty list");
return;
}
System.out.println();
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).xx+"-"+list.get(i).yy);
}
}
}
class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
} else {
continue;
}
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
class MultiTreeSet<E> {
TreeMap<E, Integer> freqTreeMap = new TreeMap<E, Integer>();
int size;
public MultiTreeSet() {}
public MultiTreeSet(Collection<? extends E> c) {
for(E element : c)
add(element);
}
public int size() {
return size;
}
public int disCount(){
return freqTreeMap.size();
}
public void add(E element) {
Integer freq = freqTreeMap.get(element);
if(freq==null)
freqTreeMap.put(element, 1);
else
freqTreeMap.put(element,freq+1);
++size;
}
public void remove(E element) {
Integer freq = freqTreeMap.get(element);
if(freq!=null) {
if(freq==1)
freqTreeMap.remove(element);
else
freqTreeMap.put(element, freq-1);
--size;
}
}
public int get(E element) {
Integer freq = freqTreeMap.get(element);
if(freq==null)
return 0;
return freq;
}
public boolean contains(E element) {
return get(element)>0;
}
public void print(){
for(E k : freqTreeMap.keySet()){
System.out.print(k+"="+freqTreeMap.get(k)+" ");
}
System.out.println();
}
public boolean isEmpty() {
return size==0;
}
public E first() {
return freqTreeMap.firstKey();
}
public E last() {
return freqTreeMap.lastKey();
}
public E ceiling(E element) {
return freqTreeMap.ceilingKey(element);
}
public E floor(E element) {
return freqTreeMap.floorKey(element);
}
public E higher(E element) {
return freqTreeMap.higherKey(element);
}
public E lower(E element) {
return freqTreeMap.lowerKey(element);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | b4c51a15cc487937323eaff2f6bbd65b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static FastReader obj = new FastReader();
public static PrintWriter out = new PrintWriter(System.out);
public static void sort(long[] a) {
ArrayList<Long> arr = new ArrayList<>();
for (int i = 0; i < a.length; i++)
arr.add(a[i]);
Collections.sort(arr);
for (int i = 0; i < arr.size(); i++)
a[i] = arr.get(i);
}
public static void revsort(long[] a) {
ArrayList<Long> arr = new ArrayList<>();
for (int i = 0; i < a.length; i++)
arr.add(a[i]);
Collections.sort(arr, Collections.reverseOrder());
for (int i = 0; i < arr.size(); i++)
a[i] = arr.get(i);
}
//Cover the small test cases like for n=1 .
public static class pair {
long a;
long b;
pair(long x, long y) {
a = x;
b = y;
}
}
public static long l() {
return obj.nextLong();
}
public static int i() {
return obj.nextInt();
}
public static String s() {
return obj.next();
}
public static long[] l(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = l();
return arr;
}
public static int[] i(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = i();
return arr;
}
public static long ceil(long a, long b) {
return (a + b - 1) / b;
}
public static void p(long val) {
out.println(val);
}
public static void p(String s) {
out.println(s);
}
public static void p(long[] arr) {
for (int i = 0; i < arr.length; i++) {
out.print(arr[i] + " ");
}
out.println();
}
public static void sortpair(ArrayList<pair> arr) {
//ascending just change return 1 to return -1 and vice versa to get descending.
//compare based on value of pair.a
arr.sort(new Comparator<pair>() {
public int compare(pair o1, pair o2) {
long val = o1.a - o2.a;
if (val == 0)
return 0;
else if (val > 0)
return 1;
else
return -1;
}
});
}
public static void main(String[] args) {
long[] b=new long[10];
b[0]=1;
b[1]=10;
for(int i=2;i<=9;i++)b[i]=b[i-1]*10;
int len = i();
while (len-- != 0) {
int n = i();
long k=l()+1;
int[] num=i(n);
Vector<Long> v=new Vector<>();
long ans=0,sum=0;
for(int i=0;i<n-1;i++)
{
v.add((long)Math.pow(10,num[i+1]-num[i])-1L);
sum+=Math.pow(10,num[i+1]-num[i])-1L;
}
long remk=k-sum;
if(sum<=k) {
ans=remk*b[num[n-1]];
k=k-remk;
}
for(int i=0;i<=n-2;i++)
{
if(k-v.get(i)<=0)
{
ans+=b[num[i]]*k;
break;
}
else
{
ans+=b[num[i]]*v.get(i);
k=k-v.get(i);
}
}
out.println(ans);
}
out.flush();
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | dd98e45c0e7bbd2d3e27effd617bf4b7 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
import java.io.*;
public class Main {
static int mod = 1000000007;
static void read(int arr[], int start, int end, FastReader in) {
for (int i = start; i < end; i++) {
arr[i] = in.nextInt();
}
}
static int sumArr(int arr[]) {
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}
static final int MAX = 10000000;
// prefix[i] is going to store count
// of primes till i (including i).
static int prefix[] = new int[MAX + 1];
static void buildPrefix() {
// Create a boolean array "prime[0..n]". A
// value in prime[i] will finally be false
// if i is Not a prime, else true.
boolean prime[] = new boolean[MAX + 1];
Arrays.fill(prime, true);
for (int p = 2; p * p <= MAX; p++) {
// If prime[p] is not changed, then
// it is a prime
if (prime[p] == true) {
// Update all multiples of p
for (int i = p * 2; i <= MAX; i += p) {
prime[i] = false;
}
}
}
// Build prefix array
prefix[0] = prefix[1] = 0;
for (int p = 2; p <= MAX; p++) {
prefix[p] = prefix[p - 1];
if (prime[p]) {
prefix[p]++;
}
}
}
static int query(int L, int R) {
return prefix[R] - prefix[L - 1];
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
static int min(int arr[]) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < arr.length; i++) {
min = Math.min(min, arr[i]);
}
return min;
}
public static void sort(int[] arr) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : arr) {
ls.add(x);
}
Collections.sort(ls);
for (int i = 0; i < arr.length; i++) {
arr[i] = ls.get(i);
}
}
static int max(int arr[]) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < arr.length; i++) {
max = Math.max(max, arr[i]);
}
return max;
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
public static boolean isPrime(long n) {
if (n < 2) {
return false;
}
if (n == 2 || n == 3) {
return true;
}
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
long sqrtN = (long) Math.sqrt(n) + 1;
for (long i = 6L; i <= sqrtN; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) {
return false;
}
}
return true;
}
static class Pair {
String first;
int second;
Pair(String f, int s) {
first = f;
second = s;
}
@Override
public String toString() {
return "first: " + first + " second: " + second;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
void read(int arr[]) {
for (int i = 0; i < arr.length; i++) {
arr[i] = nextInt();
}
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void close() throws IOException {
bw.close();
}
}
public int[] prevSmaller(int[] A){
// Stack<Integer> stk=new Stack<>();
int ans[]=new int[A.length];
int min=Integer.MAX_VALUE;
for(int k=0;k<A.length;k++){
int i=A[k];
if(i<=min){
min=i;
ans[k]=-1;
}
else if(i>min)
ans[k]=min;
}
return ans;
}
public static int count(String s, char c){
int count=0;
for(int i=0;i<s.length();i++)
if(s.charAt(i)==c)
count++;
return count;
}
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int tc=in.nextInt();
while(tc-- !=0){
int n=in.nextInt();
long k=in.nextInt();
k++;
long arr[]=new long[n];
for(int i=0;i<n;i++){
int x=in.nextInt();
arr[i]=(long)Math.pow(10,x);
}
if(n==1){
out.println(k);
continue;
}
long arr2[]=new long[n];
for(int i=0;i<n-1;i++){
// out.println("i: "+i+" arr[i]: "+arr[i]+" arr[i+1]: "+arr[i+1]);
arr2[i]=(arr[i+1]/arr[i]) - 1L;
}
arr2[n-1]=arr[n-1];
// out.println(Arrays.toString(arr));
// out.println(Arrays.toString(arr2));
long ans=0;
for(int i=0;i<n-1;i++){
long m=Math.min(k, arr2[i]);
k-=m;
ans+=m*arr[i];
// out.println("m: "+m+" k: "+k+" ans: "+ans);
if(k==0)
break;
}
if(k!=0)
ans+=k*arr2[n-1];
out.println(ans );
}
out.close();
}catch (Exception e) {
e.printStackTrace();
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4c8dc2b9cb40f8344858d0fc7b7b6bdf | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
static long mod=(long)1e9+7;
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
StringBuilder stringBuilder = new StringBuilder();
int t=Integer.parseInt(bufferedReader.readLine());
while (t-->0){
String[] strings=bufferedReader.readLine().split(" ");
int n=Integer.parseInt(strings[0]);
long k=Long.parseLong(strings[1]);
long arr[]=new long[n];
StringTokenizer stringTokenizer=new StringTokenizer(bufferedReader.readLine());
for (int i=0;i<n;i++)
arr[i]=Long.parseLong(stringTokenizer.nextToken());
long x=0,y=0,ans=0;
if (n==1)
stringBuilder.append(k+1).append("\n");
else if (k < 9)
stringBuilder.append(k+1).append("\n");
else{
k++;
for (int i=0;i<n-1;i++){
if (k > 0){
x=(long)Math.pow(10, arr[i+1]-arr[i]);
x--;
y=Math.min(x,k);
ans += (long)Math.pow(10,arr[i])*y;
k -= y;
}
else
break;;
}
if (k > 0){
y=k;
ans += (long)Math.pow(10,arr[n-1])*y;
}
stringBuilder.append(ans).append("\n");
}
}
out.print(stringBuilder);
out.close();
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4647c497af3ba98456d6dc1f523830f4 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class Main {
// Graph
// prefix sums
//inputs
public static void main(String args[])throws Exception{
Input sc=new Input();
precalculates p=new precalculates();
StringBuilder sb=new StringBuilder();
int t=sc.readInt();
for(int f=0;f<t;f++){
int d[]=sc.readArray();
int n=d[0];
long k=d[1];
long c[]=sc.readArrayLong();
// for(int i=0;i<n;i++){
// c[i]=(long)(Math.pow(10,c[i]));
// }
long total=0;
long ans=0;
int ind=-1;
for(int i=0;i<n-1;i++){
long v=(long)(Math.pow(10,c[i+1])/Math.pow(10,c[i]))-1;
if(total+v<=k) {
total +=v;
ans=ans+(long)(Math.pow(10,c[i])*v);
ind=i;
}else
break;
}
//if(k-total!=9)
ans+=(long)(Math.pow(10,c[ind+1])*(k-total+1));
//else
// ans+=(long)(Math.pow(10,c[ind+1])*(k-total+10));
sb.append(ans+"\n");
}
System.out.print(sb);
}
}
class Input{
BufferedReader br;
StringTokenizer st;
Input(){
br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer("");
}
public int[] readArray() throws Exception{
st=new StringTokenizer(br.readLine());
int a[]=new int[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Integer.parseInt(st.nextToken());
}
return a;
}
public long[] readArrayLong() throws Exception{
st=new StringTokenizer(br.readLine());
long a[]=new long[st.countTokens()];
for(int i=0;i<a.length;i++){
a[i]=Long.parseLong(st.nextToken());
}
return a;
}
public int readInt() throws Exception{
st=new StringTokenizer(br.readLine());
return Integer.parseInt(st.nextToken());
}
public long readLong() throws Exception{
st=new StringTokenizer(br.readLine());
return Long.parseLong(st.nextToken());
}
public String readString() throws Exception{
return br.readLine();
}
public int[][] read2dArray(int n,int m)throws Exception{
int a[][]=new int[n][m];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
for(int j=0;j<m;j++){
a[i][j]=Integer.parseInt(st.nextToken());
}
}
return a;
}
}
class precalculates{
public int[] prefixSumOneDimentional(int a[]){
int n=a.length;
int dp[]=new int[n];
for(int i=0;i<n;i++){
if(i==0)
dp[i]=a[i];
else
dp[i]=dp[i-1]+a[i];
}
return dp;
}
public int[] postSumOneDimentional(int a[]) {
int n = a.length;
int dp[] = new int[n];
for (int i = n - 1; i >= 0; i--) {
if (i == n - 1)
dp[i] = a[i];
else
dp[i] = dp[i + 1] + a[i];
}
return dp;
}
public int[][] prefixSum2d(int a[][]){
int n=a.length;int m=a[0].length;
int dp[][]=new int[n+1][m+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
}
}
return dp;
}
public long pow(long a,long b){
long mod=1000000007;
long ans=0;
if(b<=0)
return 1;
if(b%2==0){
ans=pow(a,b/2)%mod;
return ((ans%mod)*(ans%mod))%mod;
}else{
return ((a%mod)*(ans%mod))%mod;
}
}
}
class GraphInteger{
HashMap<Integer,vertex> vtces;
class vertex{
HashMap<Integer,Integer> children;
public vertex(){
children=new HashMap<>();
}
}
public GraphInteger(){
vtces=new HashMap<>();
}
public void addVertex(int a){
vtces.put(a,new vertex());
}
public void addEdge(int a,int b,int cost){
if(!vtces.containsKey(a)){
vtces.put(a,new vertex());
}
if(!vtces.containsKey(b)){
vtces.put(b,new vertex());
}
vtces.get(a).children.put(b,cost);
// vtces.get(b).children.put(a,cost);
}
public boolean isCyclicDirected(){
boolean isdone[]=new boolean[vtces.size()+1];
boolean check[]=new boolean[vtces.size()+1];
for(int i=1;i<=vtces.size();i++) {
if (!isdone[i] && isCyclicDirected(i,isdone, check)) {
return true;
}
}
return false;
}
private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){
if(check[i])
return true;
if(isdone[i])
return false;
check[i]=true;
isdone[i]=true;
Set<Integer> set=vtces.get(i).children.keySet();
for(Integer ii:set){
if(isCyclicDirected(ii,isdone,check))
return true;
}
check[i]=false;
return false;
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 00253d197a257e632db8168fce9ec216 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
public void prayGod() throws IOException {
int t = nextInt();
while (t-- > 0) {
int n = nextInt();
long k = nextLong();
k++;
int[] a = nextIntArray(n);
ArrayList<Long> ret = new ArrayList<>();
for (int i = 1; i < n; i++) {
if (k <= 0)
break;
long bound = (long) Math.pow(10, a[i] - a[i - 1]);
ret.add(Math.min(bound - 1, k));
k -= ret.get(ret.size() - 1);
}
if (k > 0) {
ret.add(k);
}
for (int i = ret.size() - 1; i >= 0; i--) {
out.print(ret.get(i));
}
out.println();
}
}
public long pow(int a, int b) {
if (b == 0)
return 1;
if (b == 1)
return a;
long ret = pow(a, b / 2);
if (b % 2 == 1)
ret *= a;
return ret;
}
public void printVerdict(boolean verdict) {
if (verdict)
out.println(VERDICT_YES);
else
out.println(VERDICT_NO);
}
static final String VERDICT_YES = "YES";
static final String VERDICT_NO = "NO";
static final boolean RUN_TIMING = true;
static final boolean AUTOFLUSH = false;
static final boolean FILE_INPUT = false;
static final boolean FILE_OUTPUT = false;
static int iinf = 0x3f3f3f3f;
static long inf = (long) 1e18 + 10;
static int mod = (int) 1e9 + 7;
static char[] inputBuffer = new char[1 << 20];
static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), AUTOFLUSH);
// int data-type
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public int[] nextIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
public void sort(int[] a) {
shuffle(a);
Arrays.sort(a);
}
public static void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println();
}
// long data-type
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public long[] nextLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = nextLong();
return arr;
}
public static void printArray(long[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println();
}
public void sort(long[] a) {
shuffle(a);
Arrays.sort(a);
}
// double data-type
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public double[] nextDoubleArray(int n) throws IOException {
double[] arr = new double[n];
for (int i = 0; i < n; i++)
arr[i] = nextDouble();
return arr;
}
public static void printArray(double[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println();
}
// Generic type
public <T> void sort(T[] a) {
shuffle(a);
Arrays.sort(a);
}
public static <T> void printArray(T[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println();
}
public String next() throws IOException {
int len = 0;
int c;
do {
c = in.read();
} while (Character.isWhitespace(c) && c != -1);
if (c == -1) {
throw new NoSuchElementException("Reached EOF");
}
do {
inputBuffer[len] = (char) c;
len++;
c = in.read();
} while (!Character.isWhitespace(c) && c != -1);
while (c != '\n' && Character.isWhitespace(c) && c != -1) {
c = in.read();
}
if (c != -1 && c != '\n') {
in.unread(c);
}
return new String(inputBuffer, 0, len);
}
public String nextLine() throws IOException {
int len = 0;
int c;
while ((c = in.read()) != '\n' && c != -1) {
if (c == '\r') {
continue;
}
inputBuffer[len] = (char) c;
len++;
}
return new String(inputBuffer, 0, len);
}
public boolean hasNext() throws IOException {
String line = nextLine();
if (line.isEmpty()) {
return false;
}
in.unread('\n');
in.unread(line.toCharArray());
return true;
}
public void shuffle(int[] arr) {
int n = arr.length;
for (int i = 0; i < n; i++) {
int j = (int) (Math.random() * (n - i));
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
public void shuffle(long[] arr) {
int n = arr.length;
for (int i = 0; i < n; i++) {
int j = (int) (Math.random() * (n - i));
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
public void shuffle(Object[] arr) {
int n = arr.length;
for (int i = 0; i < n; i++) {
int j = (int) (Math.random() * (n - i));
Object temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
public static void main(String[] args) throws IOException {
if (FILE_INPUT)
in = new PushbackReader(new BufferedReader(new FileReader(new File("output.txt"))), 1 << 20);
if (FILE_OUTPUT)
out = new PrintWriter(new FileWriter(new File("output.txt")));
long time = 0;
time -= System.nanoTime();
new C().prayGod();
time += System.nanoTime();
if (RUN_TIMING)
System.err.printf("%.3f ms%n", time / 1000000.0);
out.flush();
in.close();
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | e7e6292c95490090df3dde3d2b8cf7f1 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Khater
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CBanknotes solver = new CBanknotes();
solver.solve(1, in, out);
out.close();
}
static class CBanknotes {
public void solve(int testNumber, Scanner sc, PrintWriter pw) {
int t = 1;
t = sc.nextInt();
long[] pow = new long[10];
long p = 1;
for (int i = 0; i < 10; i++) {
pow[i] = p;
p *= 10;
}
while (t-- > 0) {
int n = sc.nextInt();
long k = sc.nextLong() + 1;
int[] arr = sc.nextIntArr(n);
String ans = "";
for (int i = 0; i < n - 1 && k != 0; i++) {
int dif = arr[i + 1] - arr[i];
long all = pow[dif] - 1;
long min = Math.min(all, k);
k -= min;
ans = (min) + ans;
}
if (k != 0)
pw.println(k + ans);
else pw.println(ans);
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArr(int n) {
try {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 2421e378df3b7c8768516839d1de252c | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
// THIS TEMPLATE MADE BY AKSH BANSAL.
public class Solution {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static void sort(int a[]){ // int -> long
ArrayList<Integer> arr=new ArrayList<>(); // Integer -> Long
for(int i=0;i<a.length;i++)
arr.add(a[i]);
Collections.sort(arr);
for(int i=0;i<a.length;i++)
a[i]=arr.get(i);
}
private static long gcd(long a, long b){
if(b==0)return a;
return gcd(b,a%b);
}
private static long pow(long x,long y){
if(y==0)return 1;
long temp = pow(x, y/2);
if(y%2==1){
return x*temp*temp;
}
else{
return temp*temp;
}
}
static int log(long n){
int res = 0;
while(n>0){
res++;
n/=2;
}
return res;
}
static int mod = (int)1e9+7;
static PrintWriter out;
static FastReader sc ;
public static void main(String[] args) throws IOException {
sc = new FastReader();
out = new PrintWriter(System.out);
// primes();
// ________________________________
int test = sc.nextInt();
StringBuilder output = new StringBuilder();
while (test-- > 0) {
int n = sc.nextInt();
int k = sc.nextInt();
long[] arr =new long[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
arr[i] = (int)pow(10, arr[i]);
}
output.append(solver(arr, n, k)).append("\n");
}
out.println(output);
// _______________________________
// int n = sc.nextInt();
// out.println(solver());
// ________________________________
out.flush();
}
public static long solver(long[] arr, int n, int k) {
long cur = 0;
long res = 0;
for(int i=0;i<n-1;i++){
if(res+(arr[i+1]/arr[i]-1) > k){
return cur+arr[i]*((k-res)+1);
}
else{
cur+=arr[i]*(arr[i+1]/arr[i]-1);
res+=(arr[i+1]/arr[i]-1);
}
// System.out.println(res+"__"+ cur);
}
return cur+arr[n-1]*((k-res)+1);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 021e109edbf4497aaa1e782ec1870238 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.nio.file.FileStore;
import java.util.*;
public class zia
{
static boolean prime[] = new boolean[25001];
static void BFS(ArrayList<ArrayList<Integer>> adj,int s, boolean[] visited)
{
Queue<Integer> q=new LinkedList<>();
visited[s] = true;
q.add(s);
while(q.isEmpty()==false)
{
int u = q.poll();
for(int v:adj.get(u)){
if(visited[v]==false){
visited[v]=true;
q.add(v);
}
}
}
}
static void addEdge(ArrayList<ArrayList<Integer>> adj, int u, int v)
{
adj.get(u).add(v);
adj.get(v).add(u);
}
static void ruffleSort(int[] a) {
int n=a.length;
Random random = new Random();
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
public static int Lcm(int a,int b)
{ int max=Math.max(a,b);
for(int i=1;;i++)
{
if((max*i)%a==0&&(max*i)%b==0)
return (max*i);
}
}
static void sieve(int n,boolean prime[])
{
// boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i =i+ p)
prime[i] = false;
}
}
}
// public static String run(int ar[],int n)
// {
// }
public static int upperbound(int s,int e, long ar[],long x)
{
int res=-1;
while(s<=e)
{ int mid=((s-e)/2)+e;
if(ar[mid]>x)
{e=mid-1;res=mid;}
else if(ar[mid]<x)
{s=mid+1;}
else
{e=mid-1;res=mid;
if(mid>0&&ar[mid]==ar[mid-1])
e=mid-1;
else
break;
}
}
return res;
}
public static long lowerbound(int s,int e, long ar[],long x)
{
long res=-1;
while(s<=e)
{ int mid=((s-e)/2)+e;
if(ar[mid]>x)
{e=mid-1;}
else if(ar[mid]<x)
{s=mid+1;res=mid;}
else
{res=mid;
if(mid+1<ar.length&&ar[mid]==ar[mid+1])
s=mid+1;
else
break;}
}
return res;
}
static long modulo=1000000007;
public static long power(long a, long b)
{
if(b==0) return 1;
long temp=power(a,b/2)%modulo;
if((b&1)==0)
return (temp*temp)%modulo;
else
return (((temp*temp)%modulo)*a)%modulo;
}
public static long powerwithoutmod(long a, long b)
{
if(b==0) return 1;
long temp=power(a,b/2);
if((b&1)==0)
return (temp*temp);
else
return ((temp*temp)*a);
}
public static double log2(long a)
{ double d=Math.log(a)/Math.log(2);
return d;
}
public static int log10(long a)
{ double d=Math.log(a)/Math.log(10);
return (int)d;
}
public static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
public static void tree(int s,int e,int ar[],int c)
{
if(s<=e)
{
int max=s;
for(int i=s;i<=e;i++)
if(ar[i]>ar[max])
max=i;
ar[max]=c++;
tree(s,max-1,ar,c);
tree(max+1,e,ar,c);
}
}
public static void main(String[] args) throws Exception
{
FastIO sc = new FastIO();
//sc.println();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CODE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
int test=sc.nextInt();
// // double c=Math.log(10);
// boolean prime[]=new boolean[1000000];
// sieve(1000000000, prime);
while(test-->0)
{
int n=sc.nextInt();
// ArrayList<pair> al=new ArrayList<>();
// ArrayList<pair> ar=new ArrayList<>();
// for(int i=0;i<n;i++)
// {
// int a=sc.nextInt();
// if(a!=0)
// ar.add(new pair(a,i));
// }
// Collections.sort(ar);
// int p1=ar.size()-2,p2=p1+1;
// while(p1>=0)
// {
// al.add(new pair(ar.get(p1).b,ar.get(p2).b));
// ar.get(p1).a--;
// ar.get(p2).a--;
// if(ar.get(p1).a==0)
// p1--;
// if(ar.get(p2).a==0)
// {p2=p1;p1--;}
// }
// sc.println(al.size());
// for(pair x:al)
// sc.println((x.a+1)+" "+(x.b+1));
long k=sc.nextLong();
long p10[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
int ar[]=new int[n];
for(int i=0;i<n;i++)
ar[i]=sc.nextInt();
long currMoney=0,currNotes=0;
for(int i=0;i<n;i++)
{
long currMaxNotes=0,currMaxMoney=0;
if(i==n-1)
{
currMoney=currMoney+(k-currNotes+1)*p10[ar[i]];
break;
}
currMaxMoney=p10[ar[i+1]]-p10[ar[i]];
currMaxNotes=currMaxMoney/p10[ar[i]];
if(currMaxNotes+currNotes>k)
{
currMoney=currMoney+(k-currNotes+1)*p10[ar[i]];
break;
}
else if(currMaxNotes+currNotes==k)
{
currMoney=currMoney+(currMaxNotes)*p10[ar[i]]+p10[ar[i+1]];
break;
}
currNotes+=currMaxNotes;
currMoney+=currMaxMoney;
}
sc.println(currMoney);
}
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CODE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
sc.close();
}
}
class pair implements Comparable<pair>{
long a;
long b;
pair(long a,long b)
{this.a=a;
this.b=b;
}
public int compareTo(pair p)
{return (int)(this.a-p.a);}
}
class triplet implements Comparable<triplet>{
int first,second,third;
triplet(int first,int second,int third)
{this.first=first;
this.second=second;
this.third=third;
}
public int compareTo(triplet p)
{return this.third-p.third;}
}
// class triplet
// {
// int x1,x2,i;
// triplet(int a,int b,int c)
// {x1=a;x2=b;i=c;}
// }
class FastIO extends PrintWriter {
private InputStream stream;
private byte[] buf = new byte[1<<16];
private int curChar, numChars;
// standard input
public FastIO() { this(System.in,System.out); }
public FastIO(InputStream i, OutputStream o) {
super(o);
stream = i;
}
// file input
public FastIO(String i, String o) throws IOException {
super(new FileWriter(o));
stream = new FileInputStream(i);
}
// throws InputMismatchException() if previously detected end of file
private int nextByte() {
if (numChars == -1) throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars == -1) return -1; // end of file
}
return buf[curChar++];
}
public String nextLine() {
int c; do { c = nextByte(); } while (c <= '\n');
StringBuilder res = new StringBuilder();
do { res.appendCodePoint(c); c = nextByte(); } while (c > '\n');
return res.toString();
}
public String next() {
int c; do { c = nextByte(); } while (c <= ' ');
StringBuilder res = new StringBuilder();
do { res.appendCodePoint(c); c = nextByte(); } while (c > ' ');
return res.toString();
}
public int nextInt() {
int c; do { c = nextByte(); } while (c <= ' ');
int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); }
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10*res+c-'0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public long nextLong() {
int c; do { c = nextByte(); } while (c <= ' ');
long sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); }
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = 10*res+c-'0';
c = nextByte();
} while (c > ' ');
return res * sgn;
}
public double nextDouble() { return Double.parseDouble(next()); }
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 12d559762e88b189d91bfa2b42edf6f9 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | //package random;
import java.util.*;
import java.io.*;
public class CF {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int q = Integer.parseInt(st.nextToken());
long[] pow10 = new long[10];
pow10[0] = 1;
for (int i=1; i<10; i++) {
pow10[i] = pow10[i-1]*10;
}
while(q-->0) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
k++;
long[] diff = new long[n-1];
int[] arr = new int[n];
st = new StringTokenizer(br.readLine());
for (int i=0; i<n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
for (int i=0; i<n-1; i++) {
diff[i] = pow10[arr[i+1]-arr[i]]-1;
}
long ans = 0;
for (int i=0; i<n-1; i++) {
if (diff[i]>=k) {
ans+=k*pow10[arr[i]];
k = 0;
break;
}
else {
k-=diff[i];
ans+=diff[i]*pow10[arr[i]];
}
}
if (k!=0) {
ans+=pow10[arr[n-1]]*k;
}
System.out.println(ans);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | bb9ca30f2ac3aaffdb559d16f19c7f67 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | // JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.*;
import java.lang.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.io.*;
public class CodeForces {
static private final String INPUT = "input.txt";
static private final String OUTPUT = "output.txt";
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static PrintWriter out = new PrintWriter(System.out);
static DecimalFormat df = new DecimalFormat("0.00000");
final static int MAX = Integer.MAX_VALUE, MIN = Integer.MIN_VALUE, mod = (int) (1e9 + 7);
final static long LMAX = Long.MAX_VALUE, LMIN = Long.MIN_VALUE;
final static long INF = (long) 1e18, Neg_INF = (long) -1e18;
static Random rand = new Random();
// ======================= MAIN ==================================
public static void main(String[] args) throws IOException {
long time = System.currentTimeMillis();
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
// ==== start ====
input();
preprocess();
int t = 1;
t = readInt();
while (t-- > 0) {
solve();
}
out.flush();
// ==== end ====
if (!oj)
System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
}
private static void solve() throws IOException {
int n = readInt(), k = readInt();
int[] arr = readIntArray(n);
if (arr[0] != 0)
out.println(1);
else if (n == 1)
out.println(k + 1);
else {
k++;
for (int i = 0; i < n; i++)
arr[i] = (int) Math.pow(10, arr[i]);
long ans = 0;
for (int i = 0; i < n; i++) {
int left = k;
if (i + 1 < n)
left = Math.min(left, arr[i + 1] / arr[i] - 1);
ans += 1L * arr[i] * left;
k -= left;
}
out.println(ans);
}
}
private static void preprocess() throws IOException {
}
// cd C:\Users\Eshan Bhatt\Visual Studio Code\Competitive Programming\CodeForces
// javac CodeForces.java
// java CodeForces
// javac CodeForces.java && java CodeForces
// change Stack size -> java -Xss16M CodeForces.java
// ==================== CUSTOM CLASSES ================================
static class Pair implements Comparable<Pair> {
int first, second;
Pair(int f, int s) {
first = f;
second = s;
}
public int compareTo(Pair o) {
if (this.first == o.first)
return this.second - o.second;
return this.first - o.first;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null)
return false;
if (this.getClass() != obj.getClass())
return false;
Pair other = (Pair) (obj);
if (this.first != other.first)
return false;
if (this.second != other.second)
return false;
return true;
}
@Override
public int hashCode() {
return this.first ^ this.second;
}
@Override
public String toString() {
return this.first + " " + this.second;
}
}
static class DequeNode {
DequeNode prev, next;
int val;
DequeNode(int val) {
this.val = val;
}
DequeNode(int val, DequeNode prev, DequeNode next) {
this.val = val;
this.prev = prev;
this.next = next;
}
}
// ======================= FOR INPUT ==================================
private static void input() {
FileInputStream instream = null;
PrintStream outstream = null;
try {
instream = new FileInputStream(INPUT);
outstream = new PrintStream(new FileOutputStream(OUTPUT));
System.setIn(instream);
System.setOut(outstream);
} catch (Exception e) {
System.err.println("Error Occurred.");
}
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(readLine());
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readCharacter() throws IOException {
return next().charAt(0);
}
static String readString() throws IOException {
return next();
}
static String readLine() throws IOException {
return br.readLine().trim();
}
static int[] readIntArray(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = readInt();
return arr;
}
static int[][] read2DIntArray(int n, int m) throws IOException {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++)
arr[i] = readIntArray(m);
return arr;
}
static List<Integer> readIntList(int n) throws IOException {
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(readInt());
return list;
}
static long[] readLongArray(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++)
arr[i] = readLong();
return arr;
}
static long[][] read2DLongArray(int n, int m) throws IOException {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++)
arr[i] = readLongArray(m);
return arr;
}
static List<Long> readLongList(int n) throws IOException {
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(readLong());
return list;
}
static char[] readCharArray() throws IOException {
return readString().toCharArray();
}
static char[][] readMatrix(int n, int m) throws IOException {
char[][] mat = new char[n][m];
for (int i = 0; i < n; i++)
mat[i] = readCharArray();
return mat;
}
// ========================= FOR OUTPUT ==================================
private static void printIList(List<Integer> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printLList(List<Long> list) {
for (int i = 0; i < list.size(); i++)
out.print(list.get(i) + " ");
out.println(" ");
}
private static void printIArray(int[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DIArray(int[][] arr) {
for (int i = 0; i < arr.length; i++)
printIArray(arr[i]);
}
private static void printLArray(long[] arr) {
for (int i = 0; i < arr.length; i++)
out.print(arr[i] + " ");
out.println(" ");
}
private static void print2DLArray(long[][] arr) {
for (int i = 0; i < arr.length; i++)
printLArray(arr[i]);
}
private static void yes() {
out.println("YES");
}
private static void no() {
out.println("NO");
}
// ====================== TO CHECK IF STRING IS NUMBER ========================
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static boolean isLong(String s) {
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
// ==================== FASTER SORT ================================
private static void sort(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void reverseSort(int[] arr) {
int n = arr.length;
List<Integer> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void sort(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
private static void reverseSort(long[] arr) {
int n = arr.length;
List<Long> list = new ArrayList<>(n);
for (int i = 0; i < n; i++)
list.add(arr[i]);
Collections.sort(list, Collections.reverseOrder());
for (int i = 0; i < n; i++)
arr[i] = list.get(i);
}
// ==================== MATHEMATICAL FUNCTIONS ===========================
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static int mod_pow(long a, long b, int mod) {
if (b == 0)
return 1;
int temp = mod_pow(a, b >> 1, mod);
temp %= mod;
temp = (int) ((1L * temp * temp) % mod);
if ((b & 1) == 1)
temp = (int) ((1L * temp * a) % mod);
return temp;
}
private static int multiply(int a, int b) {
return (int) ((((1L * a) % mod) * ((1L * b) % mod)) % mod);
}
private static int divide(int a, int b) {
return multiply(a, mod_pow(b, mod - 2, mod));
}
private static boolean isPrime(long n) {
for (long i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
private static long nCr(long n, long r) {
if (n - r > r)
r = n - r;
long ans = 1L;
for (long i = r + 1; i <= n; i++)
ans *= i;
for (long i = 2; i <= n - r; i++)
ans /= i;
return ans;
}
private static List<Integer> factors(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 1; 1L * i * i <= n; i++)
if (n % i == 0) {
list.add(i);
if (i != n / i)
list.add(n / i);
}
return list;
}
private static List<Long> factors(long n) {
List<Long> list = new ArrayList<>();
for (long i = 1; i * i <= n; i++)
if (n % i == 0) {
list.add(i);
if (i != n / i)
list.add(n / i);
}
return list;
}
// ==================== Primes using Seive =====================
private static List<Integer> getPrimes(int n) {
boolean[] prime = new boolean[n + 1];
Arrays.fill(prime, true);
for (int i = 2; 1L * i * i <= n; i++)
if (prime[i])
for (int j = i * i; j <= n; j += i)
prime[j] = false;
// return prime;
List<Integer> list = new ArrayList<>();
for (int i = 2; i <= n; i++)
if (prime[i])
list.add(i);
return list;
}
private static int[] SeivePrime(int n) {
int[] primes = new int[n];
for (int i = 0; i < n; i++)
primes[i] = i;
for (int i = 2; 1L * i * i < n; i++) {
if (primes[i] != i)
continue;
for (int j = i * i; j < n; j += i)
if (primes[j] == j)
primes[j] = i;
}
return primes;
}
// ==================== STRING FUNCTIONS ================================
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}
// check if a is subsequence of b
private static boolean isSubsequence(String a, String b) {
int idx = 0;
for (int i = 0; i < b.length() && idx < a.length(); i++)
if (a.charAt(idx) == b.charAt(i))
idx++;
return idx == a.length();
}
private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
private static String sortString(String str) {
int[] arr = new int[256];
for (char ch : str.toCharArray())
arr[ch]++;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 256; i++)
while (arr[i]-- > 0)
sb.append((char) i);
return sb.toString();
}
// ==================== LIS & LNDS ================================
private static int LIS(int arr[], int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find1(list, arr[i]);
if (idx < list.size())
list.set(idx, arr[i]);
else
list.add(arr[i]);
}
return list.size();
}
private static int find1(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) >= val) {
ret = mid;
j = mid - 1;
} else {
i = mid + 1;
}
}
return ret;
}
private static int LNDS(int[] arr, int n) {
List<Integer> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
int idx = find2(list, arr[i]);
if (idx < list.size())
list.set(idx, arr[i]);
else
list.add(arr[i]);
}
return list.size();
}
private static int find2(List<Integer> list, int val) {
int ret = list.size(), i = 0, j = list.size() - 1;
while (i <= j) {
int mid = (i + j) / 2;
if (list.get(mid) <= val) {
i = mid + 1;
} else {
ret = mid;
j = mid - 1;
}
}
return ret;
}
// =============== Lower Bound & Upper Bound ===========
// less than or equal
private static int lower_bound(List<Integer> list, int val) {
int ans = -1, lo = 0, hi = list.size() - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(List<Long> list, long val) {
int ans = -1, lo = 0, hi = list.size() - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(int[] arr, int val) {
int ans = -1, lo = 0, hi = arr.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private static int lower_bound(long[] arr, long val) {
int ans = -1, lo = 0, hi = arr.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] <= val) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
// greater than or equal
private static int upper_bound(List<Integer> list, int val) {
int ans = list.size(), lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(List<Long> list, long val) {
int ans = list.size(), lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (list.get(mid) >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(int[] arr, int val) {
int ans = arr.length, lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
private static int upper_bound(long[] arr, long val) {
int ans = arr.length, lo = 0, hi = ans - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] >= val) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return ans;
}
// ==================== UNION FIND =====================
private static int find(int x, int[] parent) {
if (parent[x] == x)
return x;
return parent[x] = find(parent[x], parent);
}
private static boolean union(int x, int y, int[] parent, int[] rank) {
int lx = find(x, parent), ly = find(y, parent);
if (lx == ly)
return false;
if (rank[lx] > rank[ly])
parent[ly] = lx;
else if (rank[lx] < rank[ly])
parent[lx] = ly;
else {
parent[lx] = ly;
rank[ly]++;
}
return true;
}
// ==================== TRIE ================================
static class Trie {
class Node {
Node[] children;
boolean isEnd;
Node() {
children = new Node[26];
}
}
Node root;
Trie() {
root = new Node();
}
void insert(String word) {
Node curr = root;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null)
curr.children[ch - 'a'] = new Node();
curr = curr.children[ch - 'a'];
}
curr.isEnd = true;
}
boolean find(String word) {
Node curr = root;
for (char ch : word.toCharArray()) {
if (curr.children[ch - 'a'] == null)
return false;
curr = curr.children[ch - 'a'];
}
return curr.isEnd;
}
}
// ================== SEGMENT TREE (RANGE SUM & RANGE UPDATE) ==================
public static class SegmentTree {
int n;
long[] arr, tree, lazy;
SegmentTree(long arr[]) {
this.arr = arr;
this.n = arr.length;
this.tree = new long[(n << 2)];
this.lazy = new long[(n << 2)];
build(1, 0, n - 1);
}
void build(int id, int start, int end) {
if (start == end)
tree[id] = arr[start];
else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
build(left, start, mid);
build(right, mid + 1, end);
tree[id] = tree[left] + tree[right];
}
}
void update(int l, int r, long val) {
update(1, 0, n - 1, l, r, val);
}
void update(int id, int start, int end, int l, int r, long val) {
distribute(id, start, end);
if (end < l || r < start)
return;
if (start == end)
tree[id] += val;
else if (l <= start && end <= r) {
lazy[id] += val;
distribute(id, start, end);
} else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
update(left, start, mid, l, r, val);
update(right, mid + 1, end, l, r, val);
tree[id] = tree[left] + tree[right];
}
}
long query(int l, int r) {
return query(1, 0, n - 1, l, r);
}
long query(int id, int start, int end, int l, int r) {
if (end < l || r < start)
return 0L;
distribute(id, start, end);
if (start == end)
return tree[id];
else if (l <= start && end <= r)
return tree[id];
else {
int mid = (start + end) / 2, left = (id << 1), right = left + 1;
return query(left, start, mid, l, r) + query(right, mid + 1, end, l, r);
}
}
void distribute(int id, int start, int end) {
if (start == end)
tree[id] += lazy[id];
else {
tree[id] += lazy[id] * (end - start + 1);
lazy[(id << 1)] += lazy[id];
lazy[(id << 1) + 1] += lazy[id];
}
lazy[id] = 0;
}
}
// ==================== FENWICK TREE ================================
static class FT {
int n;
int[] arr;
int[] tree;
FT(int[] arr, int n) {
this.arr = arr;
this.n = n;
this.tree = new int[n + 1];
for (int i = 1; i <= n; i++) {
update(i, arr[i - 1]);
}
}
FT(int n) {
this.n = n;
this.tree = new int[n + 1];
}
// 1 based indexing
void update(int idx, int val) {
while (idx <= n) {
tree[idx] += val;
idx += idx & -idx;
}
}
// 1 based indexing
long query(int l, int r) {
return getSum(r) - getSum(l - 1);
}
long getSum(int idx) {
long ans = 0L;
while (idx > 0) {
ans += tree[idx];
idx -= idx & -idx;
}
return ans;
}
}
// ==================== BINARY INDEX TREE ================================
static class BIT {
long[][] tree;
int n, m;
BIT(int[][] mat, int n, int m) {
this.n = n;
this.m = m;
tree = new long[n + 1][m + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
update(i, j, mat[i - 1][j - 1]);
}
}
}
void update(int x, int y, int val) {
while (x <= n) {
int t = y;
while (t <= m) {
tree[x][t] += val;
t += t & -t;
}
x += x & -x;
}
}
long query(int x1, int y1, int x2, int y2) {
return getSum(x2, y2) - getSum(x1 - 1, y2) - getSum(x2, y1 - 1) + getSum(x1 - 1, y1 - 1);
}
long getSum(int x, int y) {
long ans = 0L;
while (x > 0) {
int t = y;
while (t > 0) {
ans += tree[x][t];
t -= t & -t;
}
x -= x & -x;
}
return ans;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4662ae2e9feef49cd579050b47e9a32c | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
PrintWriter writer = new PrintWriter(System.out);
long mod = 1000000007;
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
long k = sc.nextLong()+1;
long arr[] = new long[n];
for(int i = 0; i <n ; i++) {
arr[i] = (long)Math.pow(10, sc.nextLong());
}
long vall[] = new long[n];
vall[n-1] = (long)Long.MAX_VALUE;
for(int i = n-2; i >= 0; i--) {
vall[i] = arr[i+1]/arr[i] - 1;
}
// writer.println(Arrays.toString(vall));
long ans = 0;
int i = 0;
while(k!=0) {
long p =(Math.min(k, vall[i]));
ans+= (p*arr[i]);
k-=p;
i++;
}
writer.println(ans);
}
writer.flush();
writer.close();
}
private static int find(ArrayList<Integer> listt) {
int sec = listt.get(0);
for(int i = 1; i < listt.size(); i++) {
if(listt.get(i)%10 == listt.get(i-1)%10) {
listt.remove(i);
listt.add(i, listt.get(i-1) + 10);
}
sec = Math.max(sec, listt.get(i));
}
return sec;
}
private static long power (long a, long n, long p) {
long res = 1;
while(n!=0) {
if(n%2==1) {
res=(res*a)%p;
n--;
}else {
a= (a*a)%p;
n/=2;
}
}
return res;
}
private static boolean isPrime(int c) {
for (int i = 2; i*i <= c; i++) {
if(c%i==0)return false;
}
return true;
}
private static int find(int a , int arr[]) {
if(arr[a] != a) return arr[a] = find(arr[a], arr);
return arr[a];
}
private static void union(int a, int b, int arr[]) {
int aa = find(a,arr);
int bb = find(b, arr);
arr[aa] = bb;
}
private static int gcd(int a, int b) {
if(a==0)return b;
return gcd(b%a, a);
}
public static int[] readIntArray(int size, FastReader s) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = s.nextInt();
}
return array;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
class Pair implements Comparable<Pair>{
int a;
int b;
int c;
int d;
int e;
Pair(int a, int b, int c, int d, int e){
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
}
@Override
public boolean equals(Object obj) {
if(this == obj) return true;
if(obj == null || obj.getClass()!= this.getClass()) return false;
Pair pair = (Pair) obj;
return (pair.a == this.a && pair.b == this.b);
}
@Override
public int hashCode()
{
return Objects.hash(a,b,c,d,e);
}
@Override
public int compareTo(Pair o) {
if(this.a == o.a) {
return Long.compare(this.b, o.b);
}else {
return Long.compare(this.a, o.a);
}
}
@Override
public String toString() {
return this.a + " " + this.b;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4770e3ad919acbbaf2dcebced17bbd8b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class C1606 {
public static void main(String[] args) throws IOException, FileNotFoundException {
// Scanner in = new Scanner(new File("test.in"));
Kattio in = new Kattio();
int T = in.nextInt();
while(T > 0){
T--;
int N = in.nextInt();
long K = in.nextInt() + 1;
int[] a = new int[N];
for(int i = 0; i < N; i++){
a[i] = (int) Math.pow(10, in.nextInt());
}
long ans = 0;
for(int i = 0; i < N - 1; i++){
long maxAdd = Math.min(K, (a[i + 1] - 1) / a[i]);
K -= maxAdd;
// System.out.println(maxAdd + " " + a[i]);
ans += maxAdd * a[i];
}
// System.out.println("AMOUNT BEFORE ADDING LAST CHUNK " + " " + K);
ans += ((long) K) * a[N - 1];
// and then add all of the last ones until the position is reached
System.out.println(ans);
//
// int ret = 0;
// for(int i = N - 1; i >= 0; i--){
// ret += ans / a[i];
// ans %= a[i];
// }
// System.out.println(ret);
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(problemName + ".out");
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 542cb742256c5224d0c35687b1059bc0 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
public class Main {
static final long MOD1=1000000007;
static final long MOD=998244353;
static int[] ans;
public static void main(String[] args){
PrintWriter out = new PrintWriter(System.out);
InputReader sc=new InputReader(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
long k = sc.nextLong()+1;
int[] a = sc.nextIntArray(n);
out.println(solve(n, k, a));
}
out.flush();
}
static long solve(int n, long k, int[] a) {
long[] ten = new long[19];
ten[0] = 1;
for (int i = 1; i < ten.length; i++) {
ten[i] = ten[i-1]*10;
}
long ans = 0;
for (int i = 0; i < a.length; i++) {
int next = 18;
if(i+1<n) next = a[i+1];
long sum = Math.min(k, ten[next - a[i]]-1);
k -= sum;
ans += sum * ten[a[i]];
}
return ans;
}
static class Binomial{
int MAX = 510000;//ほしいサイズ
long[] fac=new long[MAX];
long[] finv=new long[MAX];
long[] inv=new long[MAX];
public Binomial(){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[(int) (MOD%i)] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}//facがx!、finvがx!の逆元,10^7くらいまでのテーブル(MAXまで)
}
long nCk(int n,int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long fac(int n) {
return fac[n];
}
long fac_inv(int n) {
return finv[n];
}
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nextDoubleArray(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 53d1e6b0697417e9a4419a22a8bb62a0 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | // ceil using integer division: ceil(x/y) = (x+y-1)/y
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;
public class practice {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int t = Reader.nextInt();
while(t-->0){
int n = Reader.nextInt();
long k = Reader.nextLong();
long[] arr = new long[n];
for(int i = 0;i<n;i++){
arr[i] = Reader.nextLong();
}
long tot = 0;
long ans = 0;
int i = 0;
boolean flag = true;
while(i+1<n){
long pow = (long) Math.pow(10,arr[i+1]-arr[i]);
if(k>=pow-1){
tot = (long) Math.pow(10,arr[i+1]) -1 ;
k -= pow -1;
}
else{
flag = false;
if(i==0){
System.out.println(k*(long)Math.pow(10,arr[i])+1);
break;
}
ans = (long) (Math.pow(10,arr[i])*(k+1) + tot);
System.out.println(ans);
break;
}
i++;
}
if(flag){
ans = (long) (Math.pow(10,arr[i])*(k+1)) + tot;
System.out.println(ans);
}
}
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static String nextLine() throws IOException {
return reader.readLine();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException{
return Long.parseLong(next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | e37726a942bc41a2074310387c153542 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Main{
static boolean[] primecheck = new boolean[1000002];
static ArrayList<Integer>[] adj;
static int[] vis;
static int mod = (int)1e9 + 7;
public static void main(String[] args) {
OutputStream outputStream = System.out;
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(outputStream);
PROBLEM solver = new PROBLEM();
int t = 1;
t = in.ni();
for (int i = 0; i < t; i++) {
//out.print("Case #" + (i+1) + ": ");
solver.solve(in, out);
}
out.close();
}
static class PROBLEM {
public void solve(FastReader in, PrintWriter out) {
int n = in.ni(), k = in.ni(), a[] = in.ra(n);
for (int i = 0; i < n; i++) {
a[i] = (int)Math.pow(10, a[i]);
}
int cur = k+1, p = 0;
long val = 0;
while(cur > 0){
int use = 0;
if(p < n-1) use = Math.min(cur, a[p+1]/a[p] - 1);
else use = cur;
val += (long)use * a[p];
cur -= use;
if(p < n-1) p++;
}
out.println(val);
}
}
static void pa(int[] a, PrintWriter out){
for (int j : a) {
out.print(j + " ");
}
out.println();
}
static void pa(long[] a, PrintWriter out){
for (long j : a) {
out.print(j + " ");
}
out.println();
}
public static void sortbyColumn(int arr[][], int col)
{
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<int[]>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1,
final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
}); // End of function call sort().
}
static boolean isPoT(int n){
double p = Math.log((double)n)/Math.log(2D);
return (p == (int)p);
}
static void dfs(int i){
vis[i] = 1;
for(int j: adj[i]){
if(vis[j] == 0) {
dfs(j);
}
}
}
static long sigmaK(long k){
return (k*(k+1))/2;
}
static void swap(int[] a, int l, int r) {
int temp = a[l];
a[l] = a[r];
a[r] = temp;
}
static int binarySearch(int[] a, int l, int r, int x){
if(r>=l){
int mid = l + (r-l)/2;
if(a[mid] == x) return mid;
if(a[mid] > x) return binarySearch(a, l, mid-1, x);
else return binarySearch(a,mid+1, r, x);
}
return -1;
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long lcm(long a, long b){
return (a / gcd(a, b)) * b;
}
static boolean isSquare(double a) {
boolean isSq = false;
double b = Math.sqrt(a);
double c = Math.sqrt(a) - Math.floor(b);
if (c == 0) isSq = true;
return isSq;
}
static long fast_pow(long a, long b) { //Jeel bhai OP
if(b == 0)
return 1L;
long val = fast_pow(a, b / 2);
if(b % 2 == 0)
return val * val % mod;
else
return val * val % mod * a % mod;
}
static int exponentMod(int A, int B, int C) {
// Base cases
if (A == 0)
return 0;
if (B == 0)
return 1;
// If B is even
long y;
if (B % 2 == 0) {
y = exponentMod(A, B / 2, C);
y = (y * y) % C;
}
// If B is odd
else {
y = A % C;
y = (y * exponentMod(A, B - 1, C) % C) % C;
}
return (int) ((y + C) % C);
}
// static class Pair implements Comparable<Pair>{
//
// int x;
// int y;
//
// Pair(int x, int y){
// this.x = x;
// this.y = y;
// }
//
// public int compareTo(Pair o){
//
// int ans = Integer.compare(x, o.x);
// if(o.x == x) ans = Integer.compare(y, o.y);
//
// return ans;
//
//// int ans = Integer.compare(y, o.y);
//// if(o.y == y) ans = Integer.compare(x, o.x);
////
//// return ans;
// }
// }
static class Tuple implements Comparable<Tuple>{
int x, y, id;
Tuple(int x, int y, int id){
this.x = x;
this.y = y;
this.id = id;
}
public int compareTo(Tuple o){
int ans = Integer.compare(x, o.x);
if(o.x == x) ans = Integer.compare(y, o.y);
return ans;
}
}
public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
public U x;
public V y;
public Pair(U x, V y) {
this.x = x;
this.y = y;
}
public int hashCode() {
return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Pair<U, V> p = (Pair<U, V>) o;
return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
}
public int compareTo(Pair<U, V> b) {
int cmpU = x.compareTo(b.x);
return cmpU != 0 ? cmpU : y.compareTo(b.y);
}
public int compareToY(Pair<U, V> b) {
int cmpU = y.compareTo(b.y);
return cmpU != 0 ? cmpU : x.compareTo(b.x);
}
public String toString() {
return String.format("(%s, %s)", x.toString(), y.toString());
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
char nc() {
return next().charAt(0);
}
boolean nb() {
return !(ni() == 0);
}
// boolean nextBoolean(){return Boolean.parseBoolean(next());}
String nline() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] ra(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) array[i] = ni();
return array;
}
}
private static int[] mergeSort(int[] array) {
//array.length replaced with ctr
int ctr = array.length;
if (ctr <= 1) {
return array;
}
int midpoint = ctr / 2;
int[] left = new int[midpoint];
int[] right;
if (ctr % 2 == 0) {
right = new int[midpoint];
} else {
right = new int[midpoint + 1];
}
for (int i = 0; i < left.length; i++) {
left[i] = array[i];
}
for (int i = 0; i < right.length; i++) {
right[i] = array[i + midpoint];
}
left = mergeSort(left);
right = mergeSort(right);
int[] result = merge(left, right);
return result;
}
private static int[] merge(int[] left, int[] right) {
int[] result = new int[left.length + right.length];
int leftPointer = 0, rightPointer = 0, resultPointer = 0;
while (leftPointer < left.length || rightPointer < right.length) {
if (leftPointer < left.length && rightPointer < right.length) {
if (left[leftPointer] < right[rightPointer]) {
result[resultPointer++] = left[leftPointer++];
} else {
result[resultPointer++] = right[rightPointer++];
}
} else if (leftPointer < left.length) {
result[resultPointer++] = left[leftPointer++];
} else {
result[resultPointer++] = right[rightPointer++];
}
}
return result;
}
public static void Sieve(int n) {
Arrays.fill(primecheck, true);
primecheck[0] = false;
primecheck[1] = false;
for (int i = 2; i * i < n + 1; i++) {
if (primecheck[i]) {
for (int j = i * 2; j < n + 1; j += i) {
primecheck[j] = false;
}
}
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ef6e7fac88b980d40919fbab1a9dcc8e | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.io.*;
import java.util.*;
public class Del {
static int mod=(int)1e9+7;
public static void main(String[] args) {
var io = new Copied(System.in, System.out);
long ten[]=new long[10];
long j=1;
for(int i=0;i<10;i++){
ten[i]=j;
j*=10;
}
// int k=1;
int t = 1;
t = io.nextInt();
for (int i = 0; i < t; i++) {
// out.println("Case #" + k + ": ");
solve(io,ten);
// k++;
}
io.close();
}
public static void solve(Copied io,long []tens) {
int n=io.nextInt();
long k=io.nextLong();
int a[]=io.readArray(n);
long min=0,f=1,b4=0;
for(int i=0;i<n;i++){
long cur=tens[a[i]];
if(min+1<cur){
io.println(min+1);
return;
}
min=b4;
min+=(k*tens[a[i]]);
if(f==1 && i<n-1){
long h=a[i+1]-a[i];
h=tens[(int)h];
h-=2;
k-=h;
b4+=(h*tens[a[i]]);
f=0;
}
else if(i<n-1){
long h=a[i+1]-a[i];
h=tens[(int)h];
h-=1;
k-=h;
b4+=(h*tens[a[i]]);
}
// for(int j=0;j<=i;j++){
// }
}
io.println(min+1);
}
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
static int power(int x, int y, int p)
{
int res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
public static void printArr(int[] arr) {
for (int x : arr)
System.out.print(x + " ");
System.out.println();
}
public static int[] listToInt(ArrayList<Integer> a){
int n=a.size();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=a.get(i);
}
return arr;
}
static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}
static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;}
}
class Pair {
int a,b;
Pair(int a,int b) {
this.a=a;
this.b=b;
}
}
class DescendingOrder<T> implements Comparator<T>{
@Override
public int compare(Object o1,Object o2){
// -1 if want to swap and (1,0) otherwise.
int addingNumber=(Integer) o1,existingNumber=(Integer) o2;
if(addingNumber>existingNumber) return -1;
else if(addingNumber<existingNumber) return 1;
else return 0;
}
}
class Copied extends PrintWriter {
public Copied(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Copied(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public String next() {
return nextToken();
}
public double[] nextDoubles(int N) {
double[] res = new double[N];
for (int i = 0; i < N; i++) {
res[i] = nextDouble();
}
return res;
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongs(int N) {
long[] res = new long[N];
for (int i = 0; i < N; i++) {
res[i] = nextLong();
}
return res;
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) { }
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | af2f560eb528d946d05d307624539d71 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
private static FS sc = new FS();
private static class FS {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
private static class extra {
static int[] intArr(int size) {
int[] a = new int[size];
for(int i = 0; i < size; i++) a[i] = sc.nextInt();
return a;
}
static long[] longArr(int size) {
Scanner scc = new Scanner(System.in);
long[] a = new long[size];
for(int i = 0; i < size; i++) a[i] = sc.nextLong();
return a;
}
static long intSum(int[] a) {
long sum = 0;
for(int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
static long longSum(long[] a) {
long sum = 0;
for(int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
static LinkedList[] graphD(int vertices, int edges) {
LinkedList<Integer>[] temp = new LinkedList[vertices+1];
for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
for(int i = 0; i < edges; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
temp[x].add(y);
}
return temp;
}
static LinkedList[] graphUD(int vertices, int edges) {
LinkedList<Integer>[] temp = new LinkedList[vertices+1];
for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>();
for(int i = 0; i < edges; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
temp[x].add(y);
temp[y].add(x);
}
return temp;
}
static void printG(LinkedList[] temp) { for(LinkedList<Integer> aa:temp) System.out.println(aa); }
static long cal(long val, long pow, long mod) {
if(pow == 0) return 1;
long res = cal(val, pow/2, mod);
long ret = (res*res)%mod;
if(pow%2 == 0) return ret;
return (val*ret)%mod;
}
static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); }
}
static int mod = 998244353;
static long inf = (long) Long.MAX_VALUE;
// static StringBuilder out;
public static void main(String[] args) {
int t = sc.nextInt();
// int t = 1;
StringBuilder ret = new StringBuilder();
while(t-- > 0) {
int n = sc.nextInt(), k = sc.nextInt();
int[] a = extra.intArr(n);
for(int i = 0; i < n; i++) a[i] = (int) Math.pow(10, a[i]);
long sum = 0, ans = 0;
for(int i = 0; i < n; i++) {
// System.out.println(sum + " " + ans);
long val = 0;
if(i == n-1) val = (long) 1e15;
else val = a[i+1]/a[i] - 1;
if(sum + val > k) {
ans += a[i] * (k - sum + 1);
break;
}
sum += val;
ans += val * a[i];
// System.out.println(sum + " " + val + " " + ans);
}
ret.append(ans + "\n");
}
System.out.println(ret);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 7e976ccc4f649965a0814020c81e1c3f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class A {
public static void main(String[] args) throws IOException {
InputStreamReader re=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(re);
int t = Integer.parseInt(br.readLine());
int i,j;
for(i=0;i<t;i++) {
String s = br.readLine();
String [] c = s.split(" ");
int n = Integer.parseInt(c[0]);
long k = Long.parseLong(c[1]);
long[] arr = new long[n];
s = br.readLine();
String [] ce = s.split(" ");
for(j=0;j<n;j++) {
arr[j] = Long.parseLong(ce[j]);
arr[j] = (long) Math.pow(10, arr[j]);
}
if(arr[0]!=1)
System.out.println(1);
else {
long res = 0;
for(j=0;j<n-1;j++) {
long div = arr[j+1]/arr[j];
long tot = div-1;
if(k>=tot) {
k = k-tot;
res += tot*arr[j];
}
else
break;
//System.out.println(res);
}
res += arr[j]*(k+1);
System.out.println(res);
}
}
}
static long solve(long[] arr,long l,long r, int n,int k) {
int j;
if(l<=r) {
long m = l+(r-l)/2;
long sum = arr[0]+m;
for(j=1;j<n;j++) {
if((double)arr[j]> (double)(sum*k)/(double)100)
break;
sum+=arr[j];
}
if(j==n)
return solve(arr,l,m-1,n,k);
else
return solve(arr,m+1,r,n,k);
}
return l;
}
static long factorial(long n)
{
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
static long setbitNumber(long n)
{
long k = (int)(Math.log(n) / Math.log(2));
return 1 << k;
}
static void leftrotate(int arr[],int i, int n)
{
int t = arr[i];
int f;
int j = i+1;
for(;j<=n;j++) {
f = arr[j];
arr[j] = t;
t = f;
}
arr[i] = t;
}
static int search(int l, int r,int x, int[]arr) {
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return search( l, mid - 1, x,arr);
return search( mid + 1, r, x,arr);
}
return -1;
}
static long combination(long n, long k){ // nCr combination
long res = 1;
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
static long modpower(long x, long y, long p)
{
long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static int xor(int n){
// If n is a multiple of 4
if (n % 4 == 0)
return n;
// If n%4 gives remainder 1
if (n % 4 == 1)
return 1;
// If n%4 gives remainder 2
if (n % 4 == 2)
return n + 1;
return 0;
}
static int getsum(int n) // sum of digits
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static boolean isPrime(int n) // check prime
{
if (n <= 1)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 79ae9254df476d7d0429e4340d451579 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
static long[]pre = new long[10];
public static void main(String[] args) throws Exception {
// write your code here
pre[0] = 1;
for (int i = 1; i < 10; i++) {
pre[i] = pre[i - 1] * 10;
}
// for(long e : pre){
// System.out.println(e);
// }
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
int k = sc.nextInt()+1;
int[] trk = new int[n];
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
trk [i] = x;
}
// System.out.println("ashik");
long ans = 0;
for(int i = 0;i<n-1 && k > 0;i++){
int x = (int)Math.pow(10,trk[i+1]-trk[i])-1;
x = Math.min(x,k);
ans+= (long)Math.pow(10,trk[i])*x;
k-= x;
}
ans+= (long)Math.pow(10,trk[n-1])*k;
out.write(ans+"\n");
}
out.flush();
out.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ec255b00080e377c812a108ab33c5feb | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.*;
public class Main {
public static void main(String[] args){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
solve(in, out);
out.close();
}
static String reverse(String s) {
return (new StringBuilder(s)).reverse().toString();
}
static void sieveOfEratosthenes(int n, int factors[], ArrayList<Integer> ar)
{
factors[1]=1;
int p;
for(p = 2; p*p <=n; p++)
{
if(factors[p] == 0)
{
ar.add(p);
factors[p]=p;
for(int i = p*p; i <= n; i += p)
if(factors[i]==0)
factors[i] = p;
}
}
for(;p<=n;p++){
if(factors[p] == 0)
{
factors[p] = p;
ar.add(p);
}
}
}
static void sort(int ar[]) {
int n = ar.length;
ArrayList<Integer> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(ar[i]);
Collections.sort(a);
for (int i = 0; i < n; i++)
ar[i] = a.get(i);
}
static void sort1(long ar[]) {
int n = ar.length;
ArrayList<Long> a = new ArrayList<>();
for (int i = 0; i < n; i++)
a.add(ar[i]);
Collections.sort(a);
for (int i = 0; i < n; i++)
ar[i] = a.get(i);
}
static long ncr(long n, long r, long mod) {
if (r == 0)
return 1;
long val = ncr(n - 1, r - 1, mod);
val = (n * val) % mod;
val = (val * modInverse(r, mod)) % mod;
return val;
}
static int findMax(int a[], int n, int vis[], int i, int d){
if(i>=n)
return 0;
if(vis[i]==1)
return findMax(a, n, vis, i+1, d);
int max = 0;
for(int j=i+1;j<n;j++){
if(Math.abs(a[i]-a[j])>d||vis[j]==1)
continue;
vis[j] = 1;
max = Math.max(max, 1 + findMax(a, n, vis, i+1, d));
vis[j] = 0;
}
return max;
}
static void findSub(ArrayList<ArrayList<Integer>> ar, int n, ArrayList<Integer> a, int i){
if(i==n){
ArrayList<Integer> b = new ArrayList<Integer>();
for(int y:a){
b.add(y);
}
ar.add(b);
return;
}
for(int j=0;j<n;j++){
if(j==i)
continue;
a.set(i,j);
findSub(ar, n, a, i+1);
}
}
// *-------------------code starts here--------------------------------------------------*
public static void solve(InputReader sc, PrintWriter pw){
long mod=(long)1e9+7;
int t=sc.nextInt();
// int t=1;
L : while(--t>=0){
int n=sc.nextInt();
int k=sc.nextInt()+1;
long a[]=new long[n];
for(int i=0;i<n;i++){
a[i]=(long)Math.pow(10,sc.nextInt());
}
long ans=0;
for(int i=0;i<n-1;i++){
long val=(a[i+1]/a[i])-1;
if(val>k){
ans+=a[i]*k;
k=0;
break;
}
else{
ans+=a[i]*val;
k-=val;
}
}
ans+=a[n-1]*k;
pw.println(ans);
}
}
// *-------------------code ends here-----------------------------------------------------*
static void assignAnc(ArrayList<Integer> ar[],int sz[], int pa[] ,int curr, int par){
sz[curr] = 1;
pa[curr] = par;
for(int v:ar[curr]){
if(par==v)
continue;
assignAnc(ar, sz, pa, v, curr);
sz[curr] += sz[v];
}
}
static int findLCA(int a, int b, int par[][], int depth[]){
if(depth[a]>depth[b]){
a = a^b;
b = a^b;
a = a^b;
}
int diff = depth[b] - depth[a];
for(int i=19;i>=0;i--){
if((diff&(1<<i))>0){
b = par[b][i];
}
}
if(a==b)
return a;
for(int i=19;i>=0;i--){
if(par[b][i]!=par[a][i]){
b = par[b][i];
a = par[a][i];
}
}
return par[a][0];
}
static void formArrayForBinaryLifting(int n, int par[][]){
for(int j=1;j<20;j++){
for(int i=0;i<n;i++){
if(par[i][j-1]==-1)
continue;
par[i][j] = par[par[i][j-1]][j-1];
}
}
}
static long lcm(int a, int b){
return a*b/gcd(a,b);
}
static class Pair1 {
long a;
long b;
Pair1(long a, long b) {
this.a = a;
this.b = b;
}
}
static class Pair implements Comparable<Pair> {
int a;
int b;
// int c;
Pair(int a, int b) {
this.a = a;
this.b = b;
// this.c = c;
}
public int compareTo(Pair p) {
return Integer.compare(a,p.a);
}
}
static boolean isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long fast_pow(long base, long n, long M) {
if (n == 0)
return 1;
if (n == 1)
return base % M;
long halfn = fast_pow(base, n / 2, M);
if (n % 2 == 0)
return (halfn * halfn) % M;
else
return (((halfn * halfn) % M) * base) % M;
}
static long modInverse(long n, long M) {
return fast_pow(n, M - 2, M);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 9992768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
public long[] readarray(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | bcafc504a21ef60a8748cc25ad2396af | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class bank
{
public static void main(String[]args)
{
int x,y,z,b;
long c;
int n,k;
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(x=1;x<=t;x++)
{
n = sc.nextInt();
k = sc.nextInt();
k++;
long A[] = new long[n];
for(y=0;y<n;y++)
{
A[y]=sc.nextInt();
A[y]=(long)Math.pow(10,A[y]);
}
c=0;
for(z=0;z<n;z++)
{
if(z!=n-1)
{
b=(int)(A[z+1]/A[z])-1;
if(b<k)
{
c=c+b*A[z];
k=k-b;
}
else
{
c=c+k*A[z];
k=0;
}
}
else
c=c+A[z]*k;
}
System.out.println(c);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | a8b79a15200ec4c53fe5c51968b97d4f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for (int i = 0; i < q; i++) {
int n = sc.nextInt();
int k = sc.nextInt();
double[] notes = new double[n];
for (int j = 0; j < n; j++)
{
notes[j] = sc.nextInt();
}
long ans = 0;
int burles = 0;
int note = 1;
while (burles <= k)
{
// We want to calculate how much of this unit of burles will equal the next unit which is equal to gap
long gap;
// Case that we only given 1 unit
if (notes.length == 1)
{
ans = k+1;
break;
}
// Case that all the previous bank notes have been "overfilled" and can only fill the highest bank note possible
if (note == notes.length)
{
gap = k - burles + 1;
ans += gap*((long)Math.pow(10, notes[note-1]));
System.err.println(notes[note-1] + ": " + gap);
break;
}
gap = (long)(Math.pow(10, notes[note] - notes[note-1]) - 1);
if (burles + gap > k) {
// If gap + burles > k, then calculate how many burles will it take to reach k + 1
gap = k - burles + 1;
}
burles += gap;
System.err.println(notes[note-1] + ": " + gap);
// Each time add to ans based on the unit of burles or gap
ans += gap * Math.pow(10, notes[note-1]);
System.err.println(ans);
++note;
}
System.out.println(ans);
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | b1824c1d63e653d084b51ff3eb3fbe28 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter out;
static Reader in;
public static void main(String[] args) throws Exception {
input_output();
Main solver = new Main();
solver.solve();
out.close();
out.flush();
}
static int INF = (int)1e9;
static int MAXN = (int)2e6 + 5;
static int q, t, m, n, k;
void solve() throws Exception {
t = in.nextInt();
long[] pow = new long[11];
pow[0] = 1;
for (int i = 1; i <= 10; i++) pow[i] = pow[i-1]*10;
while (t --> 0) {
n = in.nextInt();
k = in.nextInt()+1;
int[] a = new int[n+1];
for (int i = 0; i < n; i++) a[i] = in.nextInt();
a[n] = a[n-1]+10;
long ans = 0;
for (int i = 0; i < n; i++) {
int dif = a[i+1] - a[i];
long take = Math.min(pow[dif]-1, k);
long add = pow[a[i]]*take;
ans += add;
k -= take;
}
out.println(ans);
}
}
static class Reader {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public Reader() {
this(System.in);
}
public Reader(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
static void input_output() throws IOException {
File f = new File("in.txt");
if (f.exists() && !f.isDirectory()) {
in = new Reader(new FileInputStream("in.txt"));
} else in = new Reader();
f = new File("out.txt");
if (f.exists() && !f.isDirectory()) {
out = new PrintWriter(new File("out.txt"));
} else out = new PrintWriter(System.out);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 60c215d29cbde321a1dbcf16ecd6970b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
// static boolean[] prime = new boolean[10000000];
final static long mod = 1000000007;
public static void main(String[] args) {
// sieve();
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
long k = in.nextInt()+1;
Integer[] a = intInput(n, in);
Arrays.sort(a);
long ans = 0;
int ind = 0;
while(k != 0) {
int note = (int)Math.pow(10, a[ind]);
int max = 0;
if(ind == n-1) {
ans += note*k;
break;
}else {
max = (int)(Math.pow(10, a[ind+1]) - note)/note;
}
if(max > k) {
ans += note*k;
break;
}else {
ans += note*max;
k-=max;
ind++;
}
}
out.println(ans);
}
out.flush();
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
static void reverseArray(int[] a) {
for (int i = 0; i < (a.length >> 1); i++) {
int temp = a[i];
a[i] = a[a.length - 1 - i];
a[a.length - 1 - i] = temp;
}
}
static Integer[] intInput(int n, InputReader in) {
Integer[] a = new Integer[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextInt();
return a;
}
static Long[] longInput(int n, InputReader in) {
Long[] a = new Long[n];
for (int i = 0; i < a.length; i++)
a[i] = in.nextLong();
return a;
}
static String[] strInput(int n, InputReader in) {
String[] a = new String[n];
for (int i = 0; i < a.length; i++)
a[i] = in.next();
return a;
}
// static void sieve() {
// for (int i = 2; i * i < prime.length; i++) {
// if (prime[i])
// continue;
// for (int j = i * i; j < prime.length; j += i) {
// prime[j] = true;
// }
// }
// }
}
class Data {
int val;
int ind;
Data(int val, int ind) {
this.val = Math.abs(val);
this.ind = ind;
}
}
class compareVal implements Comparator<Data> {
@Override
public int compare(Data o1, Data o2) {
return (o1.val - o2.val);
}
}
class compareInd implements Comparator<Data> {
@Override
public int compare(Data o1, Data o2) {
return o1.ind - o2.ind == 0 ? o1.val - o2.val : o1.ind - o2.ind;
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 17645e3a437adffec4c82a293af160bc | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class B750 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int[] pp = new int[10];
for (int p = 1, i = 0; i < 10; i++) {
pp[i] = p;
p *= 10;
}
while (t-- > 0) {
int n = sc.nextInt();
int k = sc.nextInt();
int[] aa = new int[n];
for (int i = 0; i < n; i++) aa[i] = sc.nextInt();
long ans = 0;
for (int i = 0; i < n; i++) {
int ki = (int) (i == n - 1 ? k + 1 : Math.min(k+1, pp[aa[i+1] - aa[i]] - 1));
ans += (long) ki * pp[aa[i]];
if (ki == k + 1) break;
k -= ki;
}
System.out.println(ans);
}
sc.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ae704b9744450b95f7243537984b4d22 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Test{
static FastReader scan;
static void solve(){
int n=scan.nextInt();
int notes=scan.nextInt();
notes++;
int []arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=scan.nextInt();
}
long ans=0;
for(int i=0;i<n-1;i++){
if(notes>0){
int currNotes=(int)Math.pow(10,arr[i+1]-arr[i]);
currNotes--;
currNotes=Math.min(notes,currNotes);
ans+=(long)(Math.pow(10,arr[i])*currNotes);
notes=notes-currNotes;
}
else break;
}
if(notes>0){
ans+=(long)(Math.pow(10,arr[n-1])*notes);
}
System.out.println(ans);
}
public static void main (String[] args) throws java.lang.Exception{
scan=new FastReader();
int t=scan.nextInt();
while(t-->0){
solve();
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class Pair implements Comparable<Pair>{
int e;
int wt;
Pair(int x,int y){
this.e=x;
this.wt=y;
}
@Override
public int compareTo(Pair x){
return (int)(x.wt-this.wt);
}
}
static void printLong(long []arr){
for(long x:arr)System.out.print(x+" ");
}
static void printInt(int []arr){
for(int x:arr)System.out.print(x+" ");
}
static void scanInt(int []arr){
for(int i=0;i<arr.length;i++){
arr[i]=scan.nextInt();
}
}
static void scanLong(long []arr){
for(int i=0;i<arr.length;i++){
arr[i]=scan.nextLong();
}
}
static long gcd(long a, long b){
if (b == 0)
return a;
return gcd(b, a % b);
}
static long power(long x, long y, long mod){
long res = 1;
x = x % mod;
if (x == 0)
return 0;
while (y > 0){
if ((y & 1) != 0)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
static long add(long a,long b,long mod){
a = a % mod;
b = b % mod;
return (((a + b) % mod) + mod) % mod;
}
static long sub(long a, long b,long mod){
a = a % mod;
b = b % mod;
return (((a - b) % mod) + mod) % mod;
}
static long mul(long a, long b,long mod){
a = a % mod;
b = b % mod;
return (((a * b) % mod) + mod) % mod;
}
static long mminvprime(long a, long b,long mod) {
return power(a, b - 2,mod);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4a307867656c0dc7c6f6212a20a11a59 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class Banknotes {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int testCase = 0; testCase < t; testCase++) {
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int bankNotes = k + 1;
BigInteger answer = BigInteger.ZERO;
for (int j = 0; j < a.length; j++) {
if (j + 1 < a.length) {
if (bankNotes > ((int) Math.pow(10, a[j + 1] - a[j]) - 1)) {
int z = (int) ((Math.pow(10, a[j + 1] - a[j]) - 1) * Math.pow(10, a[j]));
answer = answer.add(BigInteger.valueOf(z));
bankNotes = bankNotes - ((int) Math.pow(10, a[j + 1] - a[j]) - 1);
} else {
answer = answer.add(BigInteger.valueOf(bankNotes * (int) Math.pow(10, a[j])));
bankNotes = 0;
}
} else {
answer = answer.add(BigInteger.valueOf(bankNotes).multiply(BigInteger.valueOf((int) Math.pow(10, a[j]))));
}
}
System.out.println(answer);
}
in.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ad430337d0212e9fbe4c4837f7b8e740 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i<n; i++) {
int cases = in.nextInt();
int t = in.nextInt();
int[] berlins = new int[cases];
for(int j = 0; j<cases; j++) {
berlins[j]=in.nextInt();
}
int[] diffArray = new int[cases-1];
for(int j = 0; j<cases-1; j++) {
diffArray[j] = (int)Math.pow(10, berlins[j+1]-berlins[j])-1;
}
int copy = 0;
for(int j = 0; j<cases-1; j++) {
t-=diffArray[j];
if(t<0) {
copy = j;
t+=diffArray[copy];
j=cases;
}
else copy=j+1;
}
System.out.print(t+1);
for(int j = 0; j<berlins[copy]; j++) {
System.out.print(9);
}
System.out.println();
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 8e8395ab39d8275b79d771e6d4ea43e8 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i<n; i++) {
int cases = in.nextInt();
int t = in.nextInt();
int[] berlins = new int[cases];
for(int j = 0; j<cases; j++) {
berlins[j]=in.nextInt();
//System.out.print(berlins[j] + " ");
}
// System.out.println();
int[] diffArray = new int[cases-1];
for(int j = 0; j<cases-1; j++) {
diffArray[j] = (int)Math.pow(10, berlins[j+1]-berlins[j])-1;
//System.out.print(diffArray[j] + " ");
}
//System.out.println();
int copy = 0;
for(int j = 0; j<cases-1; j++) {
t-=diffArray[j];
if(t<0) {
copy = j;
t+=diffArray[copy];
j=cases;
}
else copy=j+1;
}
System.out.print(t+1);
for(int j = 0; j<berlins[copy]; j++) {
System.out.print(9);
}
System.out.println();
/*String test = String.format("%.0f",((t+2)*(Math.pow(10, berlins[copy]))-1));
BigInteger ans = new BigInteger(test);
ans.subtract(new BigInteger("1"));
System.out.println(ans);*/
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 629f121b2dfad41f3b66fe7fb8cc7a41 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BurlBanknotes {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n;
int t = Integer.parseInt(br.readLine());
int[] k = new int[t];
int[][] a = new int[t][];
for (int i = 0; i < t; i++) {
st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
k[i] = Integer.parseInt(st.nextToken());
a[i] = new int[n];
st = new StringTokenizer(br.readLine());
for (int j = 0; j < n; j++) {
a[i][j] = Integer.parseInt(st.nextToken());
}
}
long c;
int j;
for (int i = 0; i < t; i++) {
c = 0;
if(a[i].length == 1 || k[i] + 1 < Math.pow(10, a[i][1] - a[i][0])) {
System.out.println(k[i] + 1);
continue;
}
else {
c += (long)Math.pow(10, a[i][1] - a[i][0]) - 2;
k[i] -= Math.pow(10, a[i][1] - a[i][0]) - 2;
}
for (j = 1; j < a[i].length-1; j++) {
if(c + k[i] * (long) Math.pow(10, a[i][j]) + 1 >= (long) Math.pow(10, a[i][j+1])) {
c += (long) (Math.pow(10, a[i][j+1]-a[i][j]) - 1) * (long) Math.pow(10, a[i][j]);
k[i] -= Math.pow(10, a[i][j+1]-a[i][j]) - 1;
}
else {
c += k[i] * (long) Math.pow(10, a[i][j]);
k[i] = 0;
break;
}
}
if(j == a[i].length-1 && k[i] != 0) {
c += k[i] * (long) Math.pow(10, a[i][j]);
}
System.out.println(c+1);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 0f9c0b27cf7df8e50fe707f5ffe4bb3f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class C{
public static void main(String[] args){
FastReader sc = new FastReader();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int k=sc.nextInt()+1;
int a[]=sc.fastArray(n);
int b[]=a.clone();
for(int i=0;i<n;i++)
a[i]=(int)Math.pow(10, a[i]);
int max[]=new int [n];
if(n>1)max[0]=a[1]-1;
max[n-1]=9;
for(int i=1;i<n-1;i++) {
if(b[i+1]-1!=b[i]) {
int zero=b[i+1]-b[i];
int num=1;
while(zero>0) {
num*=10;
zero--;
}
max[i]=num-1;
}else max[i]=9;
}
long num=0L;int j=0;
while(k>0 && j<n-1) {
int x=Math.min(k, max[j]);
num+=((long)x*(long)a[j]);
j++;
k-=x;
}
if(k>0) num+=(((long)k*(long)a[n-1]));
System.out.println(num);
}
}
static class pair {
int x;int y;
pair(int x,int y){
this.x=x;
this.y=y;
}
}
static ArrayList<Integer> primeFac(int n){
ArrayList<Integer>ans = new ArrayList<Integer>();
int lp[]=new int [n+1];
Arrays.fill(lp, 0); //0-prime
for(int i=2;i<=n;i++) {
if(lp[i]==0) {
for(int j=i;j<=n;j+=i) {
if(lp[j]==0) lp[j]=i;
}
}
}
int fac=n;
while(fac>1) {
ans.add(lp[fac]);
fac=fac/lp[fac];
}
print(ans);
return ans;
}
static ArrayList<Long> prime_in_given_range(long l,long r){
ArrayList<Long> ans= new ArrayList<>();
int n=(int)Math.sqrt(r)+1;
int prime[]=sieve_of_Eratosthenes(n);
long res[]=new long [(int)(r-l)+1];
for(int i=0;i<=r-l;i++) {
res[i]=i+l;
}
for(int i=0;i<prime.length;i++) {
if(prime[i]==1) {
System.out.println(2);
for(int j=Math.max((int)i*i, (int)(l+i-1)/i*i);j<=r;j+=i) {
res[j-(int)l]=0;
}
}
}
for(long i:res) if(i!=0)ans.add(i);
return ans;
}
static int [] sieve_of_Eratosthenes(int n) {
int prime[]=new int [n];
Arrays.fill(prime, 1); // 1-prime | 0-not prime
prime[0]=prime[1]=0;
for(int i=2;i<n;i++) {
if(prime[i]==1) {
for(int j=i*i;j<n;j+=i) {
prime[j]=0;
}
}
}
return prime;
}
static long binpow(long a,long b) {
long res=1;
if(b==0)return a;
if(a==0)return 1;
while(b>0) {
if((b&1)==1) {
res*=a;
}
a*=a;
b>>=1;
}
return res;
}
static void print(int a[]) {
System.out.println(a.length);
for(int i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(long a[]) {
System.out.println(a.length);
for(long i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static void print(ArrayList<Integer> a) {
System.out.println(a.size());
for(long i:a) {
System.out.print(i+" ");
}
System.out.println();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
int [] fastArray(int n) {
int a[]=new int [n];
for(int i=0;i<n;i++) {
a[i]=nextInt();
}
return a;
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 7903f5271799223096cb76dd9a62d73e | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.Scanner;
public class Simple{
public static void main(String args[]){
//System.out.println("Hello Java");
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t>0){
int n = s.nextInt();
int k = s.nextInt();
int arr[] = new int[n];
long[] arr2 = new long[n];
for(int i=0;i<n;i++)arr[i]=s.nextInt();
for(int i=0;i<n;i++){
arr2[i] = (long)Math.pow(10,(arr[i]));
}
int max_curr = n;
long dp[] = new long[n];
for(int i=0;i<n-1;i++){
//long ul = (long)Math.pow(10, arr[i+1]);
//System.out.println(arr2[i]);
dp[i+1] = (arr2[i+1]-1)/arr2[i] + dp[i];
if(dp[i+1]>k){
max_curr = i;
break;
}
}
long ans =0;
if(max_curr==n){
long k1 = (long)k;
k1 = k1 - (dp[n-1]-1);
ans = k1*(arr2[n-1]) + (arr2[n-1]-1);
}
else{
long k1 = (long)k;
k1 = k1 - (dp[max_curr]-1);
ans = k1*arr2[max_curr] + (arr2[max_curr]-1);
//System.out.println(k1);
}
System.out.println(ans);
// for(int i=0;i<n;i++){
// System.out.print(arr2[i]+" ");
// }
// System.out.println();
// for(int i=0;i<n;i++){
// System.out.print(dp[i]+" ");
// }
t--;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 831faa0c607df129904f92c4eb9bee8e | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static long mod = 1000000007;
static long max ;
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while( t-- > 0) {
int n = sc.nextInt();
long k = sc.nextLong();
int arr[] = new int[n];
for( int i =0 ; i< n ;i++) {
arr[i] = sc.nextInt();
}
k++;
long temp = 0;
for( int i =0 ; i< n-1 && k > 0 ;i++) {
long s = (long)Math.pow(10, arr[i]);
long m = (long)(Math.pow(10, arr[i+1])/Math.pow(10 , arr[i]))- 1;
m = Math.min(k, m);
temp += m*(long)Math.pow(10 , arr[i]);
k-=m;
// out.println(s + " " + i+" " + k +" " + temp);
}
if( k != 0) {
temp+=k*(long)Math.pow(10 , arr[n-1]);
}
out.println(temp);
}
out.flush();
}
public static boolean ifpowof2(long n ) {
return ((n&(n-1)) == 0);
}
public static int[] nextLargerElement(int[] arr, int n) {
Stack<Integer> stack = new Stack<>();
int rtrn[] = new int[n];
rtrn[n-1] = -1;
stack.push( n-1);
for( int i = n-2 ;i >= 0 ; i--){
int temp = arr[i];
int lol = -1;
while( !stack.isEmpty() && arr[stack.peek()] <= temp){
if(arr[stack.peek()] == temp ) {
lol = stack.peek();
}
stack.pop();
}
if( stack.isEmpty()){
if( lol != -1) {
rtrn[i] = lol;
}
else {
rtrn[i] = -1;
}
}
else{
rtrn[i] = stack.peek();
}
stack.push( i);
}
return rtrn;
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a / gcd(a, b)) * b;
}
static long rightmostsetbit(long n) {
return n&-n;
}
static long leftmostsetbit(long n)
{
long k = (long)(Math.log(n) / Math.log(2));
return 1 << k;
}
static HashMap<Long,Long> primefactor( long n){
HashMap<Long ,Long> hm = new HashMap<>();
long temp = 0;
while( n%2 == 0) {
temp++;
n/=2;
}
if( temp!= 0) {
hm.put( 2L, temp);
}
long c = (long)Math.sqrt(n);
for( long i = 3 ; i <= c ; i+=2) {
temp = 0;
while( n% i == 0) {
temp++;
n/=i;
}
if( temp!= 0) {
hm.put( i, temp);
}
}
if( n!= 1) {
hm.put( n , 1L);
}
return hm;
}
@SuppressWarnings("unused")
private static ArrayList<Integer> allfactors(int abs) {
HashMap<Integer,Integer> hm = new HashMap<>();
ArrayList<Integer> rtrn = new ArrayList<>();
for( int i = 2 ;i*i <= abs; i++) {
if( abs% i == 0) {
hm.put( i , 0);
hm.put(abs/i, 0);
}
}
for( int x : hm.keySet()) {
rtrn.add(x);
}
if( abs != 0) {
rtrn.add(abs);
}
return rtrn;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 81a6950d76a6b87d2a8b83704d434794 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Aqueous {
static MyScanner sc = new MyScanner();
public static void main(String[] args) {
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
long k = sc.nextLong();
int a[] = new int[n];
long ar[] = new long[n];
for(int i= 0; i<n; i++) {
a[i] = sc.nextInt();
ar[i] = (long)Math.pow((double)10, (double)a[i]);
}
k++;
long num = 0;
for(int i= 0; i<n-1; i++) {
if(k<=9) {
num += k*(ar[i]);
break;
}
long times = ar[i+1]/ar[i];
times--;
if(times>=k) {
num = num+(k)*ar[i];
break;
}
num = num + (times)*ar[i];
k-= times;
if(i==n-2) {
num += ar[i+1]*k;
break;
}
}
if(n==1) {
long ans = k/ar[0];
if(k%ar[0]!=0) {
ans++;
}
System.out.println(ans);
}
else {
System.out.println(num);
}
}
}
static void ruffleSort(int a[]) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < n; i++) {
int oi = r.nextInt(n);
int temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(long a[]) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < n; i++) {
int oi = r.nextInt(n);
long temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 8b4d93183216aee7394eea17859d2b5e | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
//----------- StringBuilder for faster output------------------------------
static StringBuilder out = new StringBuilder();
public static void main(String[] args) {
FastScanner fs=new FastScanner();
/****** CODE STARTS HERE *****/
// System.out.println((long)1e9);
// long d = (long)1e9+1 - 9*9;
// System.out.println(d);
long[] pre = {1, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999};
long[] pre_ = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
int t = fs.nextInt();
while(t-->0) {
int n=fs.nextInt(), k=fs.nextInt();
int[] a = fs.readArray(n);
long sum = 0;
long res = k+1;
for(int i=1; i<n; i++) {
sum += pre[a[i]-a[i-1]];
// System.out.println(sum);
long temp = (k+1 - sum)*pre_[a[i]] + pre[a[i]];
// System.out.println(temp);
if(temp < 0)break;
res = temp;
}
out.append(res+"\n");
}
System.out.print(out);
}
static int countDigit(long n)
{
int count = 0;
while (n != 0) {
n = n / 10;
++count;
}
return count;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//----------- FastScanner class for faster input---------------------------
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 3a42d232d72e8c0f867aa2a8346005a3 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import com.sun.security.jgss.GSSUtil;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class javacp{
static FastReader fs=new FastReader();
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}catch (IOException e){
e.printStackTrace();
}
return str;
}
int[] inputIntArray(int n){
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = fs.nextInt();
return arr;
}
}
static void sort(int[] arr){
ArrayList<Integer> al = new ArrayList<>();
for(int val : arr){
al.add(val);
}
Collections.sort(al);
for(int i=0;i<arr.length;i++){
arr[i] = al.get(i);
}
}
static class Pair implements Comparable<Pair>{
int src;
int dest;
long wt;
Pair(int src,int dest,long wt){
this.src = src;
this.dest = dest;
this.wt = wt;
}
public int compareTo(Pair pair){
if(this.wt > pair.wt)
return 1;
else if(this.wt < pair.wt)
return -1;
else
return 0;
}
}
static int[] par1 , rank1 , size;
static int[] par2;
static int[] rank2;
static boolean union1(int vt1 , int vt2){
int parent1 = findParent1(vt1) , parent2 = findParent1(vt2);
int r1 = rank1[parent1] , r2 = rank1[parent2];
if(parent1 == parent2) return false;
if(r1 < r2) {
par1[parent1] = parent2;
size[parent2] += size[parent1];
}
else{
par1[parent2] = parent1;
size[parent1] += size[parent2];
}
if(r1 == r2) rank1[parent1]++;
return true;
}
static void union2(int vt1 , int vt2){
int parent1 = findParent2(vt1) , parent2 = findParent2(vt2);
int r1 = rank2[parent1] , r2 = rank2[parent2];
if(parent1 == parent2) return;
if(r1 < r2)
par2[parent1] = parent2;
else par2[parent2] = parent1;
if(r1 == r2) rank2[parent1]++;
}
static int findParent1(int vt){
if(par1[vt] == vt) return vt;
par1[vt] = findParent1(par1[vt]);
return par1[vt];
}
static int findParent2(int vt){
if(par2[vt] == vt) return vt;
par2[vt] = findParent2(par2[vt]);
return par2[vt];
}
static void initialise1(int numOfVtces){
par1 = new int[numOfVtces];
rank1 = new int[numOfVtces];
size = new int[numOfVtces];
for(int i=0;i<numOfVtces;i++){
par1[i] = i;
rank1[i] = 1;
size[i] = 1;
}
}
static void initialise2(int numOfVtces){
par2 = new int[numOfVtces];
rank2 = new int[numOfVtces];
for(int i=0;i<numOfVtces;i++){
par2[i] = i;
rank2[i] = 0;
}
}
public static void main(String[] args) throws IOException{
int t = 1;
t = fs.nextInt();
while (t-- > 0) {
int n = fs.nextInt() , k = fs.nextInt() + 1;
int[] arr = fs.inputIntArray(n);
long[] count = new long[n];
for(int i=0; i<n-1;i++){
long val1 = (long) Math.pow(10,arr[i]);
long val2 = (long) Math.pow(10,arr[i+1]);
count[i] = (val2-val1)/val1;
}
long[] occ = new long[n];
for(int i=0; i< n-1; i++){
if(k > count[i]){
occ[i] = count[i];
k -= count[i];
}
else{
occ[i] = k;
k = 0;
break;
}
}
if(k > 0) {
occ[n - 1] = k;
}
long num = 0;
for(int i=0; i < n; i++){
num += (occ[i] * (long) Math.pow(10,arr[i]));
}
System.out.println(num);
}
}
static int modInverse(int a, int m)
{
int m0 = m;
int y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
int q = a / m;
int t = m;
// m is remainder now, process
// same as Euclid's algo
m = a % m;
a = t;
t = y;
// Update x and y
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
static int mod = 1000000007;
static long power(long a,long b,long m) {
a %= m;
long res = 1;
while (b > 0) {
if ((b & 1) == 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
static class CustomSort implements Comparator<int[]> {
public int compare(int[] a, int[] b)
{
return a[0] - b[0];
}
}
static void printArr(int[] arr){
for(int i=0;i< arr.length;i++)
{
System.out.print(arr[i] + " ");
}
System.out.println();
}
private static int lcm(int a, int b) {
int gcd = gcd(a,b);
return (int)((long)a*(long)b)/gcd ;
}
private static int gcd(int a, int b) {
if(b == 0) return a;
else return gcd(b , a % b);
}
private static void swap(int[] arr, int start, int rand_pivot) {
int temp = arr[start];
arr[start] = arr[rand_pivot];
arr[rand_pivot] = temp;
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | cbabcd6098c338c9f09756015d08fe8f | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class Main {
static class Pair<U, V> {
public final U first;
public final V second;
public Pair(U first, V second) {
this.first = first;
this.second = second;
}
public static <U, V> Pair<U, V> of(U a, V b) {
return new Pair<>(a, b);
}
final int a = 2;
@Override
public int hashCode() {
int hash = 5;
hash = 17 * hash + this.a;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Pair other = (Pair) obj;
if (this.a != other.a) {
return false;
}
return true;
}
}
//----------------------------------------------------------------------------------------------
public static void main(String hi[]) throws Exception {
FastReader sc = new FastReader();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long k = 1L * sc.nextLong();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
Arrays.sort(a);
long[] arr = new long[n];
for(int i=0;i<n;i++)
{
int temp=a[i];
long x=1;
while(temp>0)
{
x*=10;
temp--;
}
arr[i]=x;
}
// for(int i=0;i<n;i++)
// System.out.print(arr[i]+" ");
// System.out.println();
k++;
long ans=0L;
for(int i=0;i<n-1;i++)
{
long x=Math.min((arr[i+1]-arr[i])/arr[i],k);
ans+=x*arr[i];
k-=x;
// System.out.println(ans+" "+k+" "+x);
if(k==0)
break;
}
if(k>0)
{
ans+=k*arr[n-1];
}
System.out.println(ans);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 67742e3fca2891b3ea8cd0106d362057 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.io.*;
import java.math.*;
import java.util.*;
// @author : Dinosparton
public class test {
static class Pair{
long x;
long y;
Pair(long x,long y){
this.x = x;
this.y = y;
}
}
static class Sort implements Comparator<Pair>
{
@Override
public int compare(Pair a, Pair b)
{
if(a.x!=b.x)
{
return (int)(a.x - b.x);
}
else
{
return (int)(a.y-b.y);
}
}
}
static class Compare {
void compare(Pair arr[], int n)
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
if(p1.x!=p2.x) {
return (int)(p1.x - p2.x);
}
else {
return (int)(p1.y - p2.y);
}
}
});
// for (int i = 0; i < n; i++) {
// System.out.print(arr[i].x + " " + arr[i].y + " ");
// }
// System.out.println();
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String args[]) throws Exception {
Scanner sc = new Scanner();
StringBuilder res = new StringBuilder();
int tc = sc.nextInt();
while(tc-->0) {
int n = sc.nextInt();
long k = sc.nextLong()+1;
int a[] = new int[n];
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
}
long cnt = 0;
for(int i=0;i<n-1;i++) {
if(k>0) {
long temp = (long)Math.pow(10, a[i+1]-a[i])-1;
long val = Math.min(temp, k);
k-= val;
cnt += Math.pow(10, a[i])*val;
}
else {
break;
}
}
if(k>0)
cnt += (long)Math.pow(10, a[n-1])*k;
res.append(cnt+"\n");
}
System.out.println(res);
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | adc32984bbc630368a248b87d9502c48 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
// static int mod = 998244353 ;
// static int N = 200005;
// static long factorial_num_inv[] = new long[N+1];
// static long natual_num_inv[] = new long[N+1];
// static long fact[] = new long[N+1];
// static void InverseofNumber()
//{
// natual_num_inv[0] = 1;
// natual_num_inv[1] = 1;
// for (int i = 2; i <= N; i++)
// natual_num_inv[i] = natual_num_inv[mod % i] * (mod - mod / i) % mod;
//}
//static void InverseofFactorial()
//{
// factorial_num_inv[0] = factorial_num_inv[1] = 1;
// for (int i = 2; i <= N; i++)
// factorial_num_inv[i] = (natual_num_inv[i] * factorial_num_inv[i - 1]) % mod;
//}
//static long nCrModP(long N, long R)
//{
// long ans = ((fact[(int)N] * factorial_num_inv[(int)R]) % mod * factorial_num_inv[(int)(N - R)]) % mod;
// return ans%mod;
//}
//static boolean prime[];
//static void sieveOfEratosthenes(int n)
//{
// prime = new boolean[n+1];
// for (int i = 0; i <= n; i++)
// prime[i] = true;
// for (int p = 2; p * p <= n; p++)
// {
// // If prime[p] is not changed, then it is a
// // prime
// if (prime[p] == true)
// {
// // Update all multiples of p
// for (int i = p * p; i <= n; i += p)
// prime[i] = false;
// }
// }
//}
public static void main (String[] args) throws java.lang.Exception
{
// InverseofNumber();
// InverseofFactorial();
// fact[0] = 1;
// for (long i = 1; i <= 2*100000; i++)
// {
// fact[(int)i] = (fact[(int)i - 1] * i) % mod;
// }
FastReader scan = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = scan.nextInt();
while(t-->0){
int n = scan.nextInt();
long k = scan.nextLong();
long a[] = new long[n];
for(int i=0;i<n;i++){
a[i] = scan.nextLong();
a[i] = bin_exp_mod(10,a[i]);
}
long sum = 0;
int i = 1;
if(n==1)
pw.println(k+1);
else{
for(i=1;i<n;i++){
long x = a[i]/a[i-1]-1;
if(k>=x){
sum = sum+x*a[i-1];
}
else{
sum = sum+k*a[i-1];
if(i==1)
sum = sum+1;
break;
}
if(i==1)
k = k-x+1;
else
k = k-x;
}
if(i==n){
sum = sum+k*a[i-1];
}
pw.println(sum);}
pw.flush();
}
}
static long bin_exp_mod(long a,long n){
long res = 1;
if(a==0)
return 0;
while(n!=0){
if(n%2==1){
res = ((res)*(a));
}
n = n/2;
a = ((a)*(a));
}
return res;
}
// static long gcd(long a,long b){
// if(a==0)
// return b;
// return gcd(b%a,a);
// }
// static long lcm(long a,long b){
// return (a/gcd(a,b))*b;
// }
}
//class Pair{
// Integer x,y;
// Pair(int x,int y){
// this.x = x;
// this.y = y;
// }
// public boolean equals(Object obj) {
// // TODO Auto-generated method stub
// if(obj instanceof Pair)
// {
// Pair temp = (Pair) obj;
// if(this.x.equals(temp.x) && this.y.equals(temp.y))
// return true;
// }
// return false;
// }
// @Override
// public int hashCode() {
// // TODO Auto-generated method stub
// return (this.x.hashCode() + this.y.hashCode());
// }
//}
//class Compar implements Comparator<Pair>{
// public int compare(Pair p1,Pair p2){
// return p1.x-p2.x;
// }
//}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 48d39f2266968dc49a74de0b3f009f8c | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class JavaApplication1 {
static ArrayList<String> arr = new ArrayList<>();
static int num = 0;
static long mod = (long) 1e9 + 7;
public static void main(String[] args) throws IOException {
BufferedWriter print = new BufferedWriter(new OutputStreamWriter(System.out));
fast in = new fast();
int t = in.nextInt();
while (t-- != 0) {
int n = in.nextInt();
long k = in.nextLong() + 1;
long ans = 0;
long[] arr = new long[n];
boolean check = true;
long x = 0;
for (int i = 0; i < n; i++) {
arr[i] = in.nextLong();
}
for (int i = 0; i < n - 1; i++) {
if (k > 0) {
long temp = (fastPower(10, arr[i + 1] - arr[i]) - 1);
long value = Math.min(temp, k);
ans += fastPower(10, arr[i]) * value;
k -= value;
}
}
if (k > 0) {
ans += k * fastPower(10, arr[n - 1]);
}
System.out.println(ans);
}
}
public static long fastPower(long x, long y) {
long result = 1;
while (y > 0) {
if ((y & 1) == 0) {
x *= x;
y >>>= 1;
} else {
result *= x;
y--;
}
}
return result;
}
public static long binpow(long a, long b) {
a %= mod;
long out = 1;
while (b > 0) {
if ((b & 1) != 1) {
} else {
out = (out * a % mod);
}
a = (a * a % mod);
b >>= 1;
}
return out;
}
static long LowerBound(long a[], long x) {
long l = -1, r = a.length;
while (l + 1 < r) {
long m = (l + r) >>> 1;
if (a[(int) m] >= x) {
r = m;
} else {
l = m;
}
}
return r;
}
public static boolean isPrime(long num) {
if (num <= 1) {
return false;
} else {
long sq = (long) Math.sqrt(num) + 1;
for (long i = 2; i < sq; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
public static boolean checkPalindrome(String x) {
String temp = "";
if (x.length() % 2 == 0) {
for (int i = x.subSequence(x.length() / 2, x.length()).length() - 1; i >= 0; i--) {
temp += x.subSequence(x.length() / 2, x.length()).charAt(i);
}
return x.substring(0, x.length() / 2).equals(temp);
} else {
for (int i = x.subSequence(x.length() / 2, x.length()).length() - 1; i > 0; i--) {
temp += x.subSequence(x.length() / 2, x.length()).charAt(i);
}
return x.substring(0, x.length() / 2).equals(temp);
}
}
public static boolean isVowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
return true;
} else {
return false;
}
}
public static void sub(String s, String ans) {
if (s.length() == 0) {
arr.add(ans);
return;
}
sub(s.substring(1), ans + s.charAt(0));
sub(s.substring(1), ans);
}
public static long gcd(long a, long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static class fast {
BufferedReader br;
StringTokenizer st;
public fast() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
double nextFloat() {
return Float.parseFloat(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | a99cfe435d8656c3b508eb6c4069ffaf | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class Main implements Runnable {
int n, m, k;
long n1, s;
static boolean use_n_tests = true;
long mod = 1_000_000_007;
static long mod1 = 998244353L;
List<Integer> primes = Collections.emptyList(); // generatePrimes(31623);
Map<Long, Integer> dp;
Integer[] a;
Graph graph;
void solve(FastScanner in, PrintWriter out, int testNumber) {
n = in.nextInt();
long k = in.nextInt();
a = in.nextArray2(n);
Set<Integer> has = new HashSet<>(Arrays.asList(a));
long ans = 0;
long prev = 0;
long cur9 = 9;
for (int i = 0; k >= 0; i++) {
if (has.contains(i)) {
long value = pow(10, i);
long mn = Math.min(k + 1, cur9 / value);
k -= mn;
ans += mn * 1L * value;
prev = value;
} else {
long mn = Math.min(k + 1, cur9 / prev);
k -= mn;
ans += mn * 1l * prev;
}
cur9 *= 10L;
}
out.println(ans);
}
long pow(int a, int b) {
return (long) Math.pow(10, b);
}
// ****************************** template code ***********
static boolean use_file_input_output = false;
static String input_file = "1.txt";
static String output_file = "output12.txt";
static public class LcaSparseTable {
int len;
int[][] up;
int[] tin;
int[] tout;
int time;
static List<Integer>[] tree;
static LcaSparseTable t;
void dfs(List<Integer>[] tree, int u, int p) {
tin[u] = time++;
up[0][u] = p;
for (int i = 1; i < len; i++)
up[i][u] = up[i - 1][up[i - 1][u]];
for (int v : tree[u])
if (v != p)
dfs(tree, v, u);
tout[u] = time++;
}
public LcaSparseTable(List<Integer>[] tree, int root) {
int n = tree.length;
len = 1;
while ((1 << len) <= n) ++len;
up = new int[len][n];
tin = new int[n];
tout = new int[n];
dfs(tree, root, root);
}
boolean isParent(int parent, int child) {
return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}
public int lca(int a, int b) {
if (isParent(a, b))
return a;
if (isParent(b, a))
return b;
for (int i = len - 1; i >= 0; i--)
if (!isParent(up[i][a], b))
a = up[i][a];
return up[0][a];
}
public static int getLca(int a, int b) {
return t.lca(a, b);
}
}
List<Integer> factorize(int a) {
List<Integer> res = new ArrayList<>();
for (int i = 0; i < primes.size(); i++) {
int p = primes.get(i);
while (a % p == 0) {
res.add(p);
a /= p;
}
if (a == 1 && p > a) {
break;
}
}
if (a != 1) {
res.add(a);
}
return res;
}
void impossible() {
out.println(-1);
}
void yes() {
out.println("YES");
}
void no() {
out.println("NO");
}
static boolean next_permutation(char[] p) {
for (int a = p.length - 2; a >= 0; --a)
if (p[a] < p[a + 1])
for (int b = p.length - 1; ; --b)
if (p[b] > p[a]) {
char t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
return false;
}
public static class DisjointSets {
int[] p;
int[] size;
int sccCount;
DisjointSets(int size) {
p = new int[size];
this.size = new int[size];
for (int i = 0; i < size; i++) {
this.size[i] = 1;
p[i] = i;
}
sccCount = size;
}
public int root(int x) {
return x == p[x] ? x : (p[x] = root(p[x]));
}
public void unite(int a, int b) {
a = root(a);
b = root(b);
if (a == b) {
return;
}
if (size[b] > size[a]) {
int tmp = a;
a = b;
b = tmp;
}
size[a] += size[b];
p[b] = a;
sccCount--;
}
int size(int id) {
return size[root(id)];
}
}
boolean triangleCheck(int a, int b, int c) {
return a + b > c && a + c > b && b + c > a;
}
Map<Integer, Integer> numberCompression(List<Integer> ls) {
Collections.sort(ls);
int id = 1;
Map<Integer, Integer> comp = new HashMap<>();
for (int num : ls) {
if (!comp.containsKey(num)) {
comp.put(num, id++);
}
}
return comp;
}
long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
int gcd(int a, int b) {
return (int) gcd(a, (long) b);
}
class Pt {
int x, y;
Pt(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
boolean sameAxis(Pt b) {
return b.x == x || b.y == y;
}
int manxDist(Pt b) {
return Math.abs(x - b.x) + Math.abs(y - b.y);
}
void read() {
x = in.nextInt();
y = in.nextInt();
}
long getHash() {
return x * 1000000000L + (long) y;
}
}
void swap(Integer[] a, int i, int j) {
Integer tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
void swap(List<Integer> a, int i, int j) {
Integer tmp = a.get(i);
a.set(i, a.get(j));
a.set(j, tmp);
}
long manhDist(long x, long y, long x1, long y1) {
return Math.abs(x - x1) + Math.abs(y - y1);
}
double dist(double x, double y, double x1, double y1) {
return Math.sqrt(Math.pow(x - x1, 2.0) + Math.pow(y - y1, 2.0));
}
public static class FW {
public static void add(long[] t, int i, long value) {
for (; i < t.length; i |= i + 1)
t[i] += value;
}
public static long sum(long[] t, int i) {
long res = 0;
for (; i >= 0; i = (i & (i + 1)) - 1)
res += t[i];
return res;
}
public static void add(long[] t, int a, int b, long value) {
add(t, a, value);
add(t, b + 1, -value);
}
}
int sign(int a) {
if (a < 0) {
return -1;
}
return 1;
}
long binpow(long a, int b) {
long res = 1;
while (b != 0) {
if (b % 2 == 0) {
b /= 2;
a *= a;
a %= mod;
}
b--;
res *= a;
res %= mod;
}
return res;
}
List<Integer> getDigits(long n) {
List<Integer> res = new ArrayList<>();
while (n != 0) {
res.add((int) (n % 10L));
n /= 10;
}
return res;
}
List<Integer> generatePrimes(int n) {
List<Integer> res = new ArrayList<>();
boolean[] sieve = new boolean[n + 1];
for (int i = 2; i <= n; i++) {
if (!sieve[i]) {
res.add(i);
}
if ((long) i * i <= n) {
for (int j = i * i; j <= n; j += i) {
sieve[j] = true;
}
}
}
return res;
}
static int stack_size = 1 << 29;
static class Coeff {
long mod;
long[][] C;
long[] fact;
boolean cycleWay = false;
Coeff(int n, long mod) {
this.mod = mod;
fact = new long[n + 1];
fact[0] = 1;
for (int i = 1; i <= n; i++) {
fact[i] = i;
fact[i] %= mod;
fact[i] *= fact[i - 1];
fact[i] %= mod;
}
}
Coeff(int n, int m, long mod) {
// n > m
cycleWay = true;
this.mod = mod;
C = new long[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= Math.min(i, m); j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
C[i][j] %= mod;
}
}
}
}
public long fact(int n) {
return fact[n];
}
public long C(int n, int m) {
if (cycleWay) {
return C[n][m];
}
return fC(n, m);
}
private long fC(int n, int m) {
return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod;
}
private long inv(long r) {
if (r == 1)
return 1;
return ((mod - mod / r) * inv(mod % r)) % mod;
}
}
class Pair {
int first;
long second;
Pair(int f, long s) {
first = f;
second = s;
}
public int getFirst() {
return first;
}
public long getSecond() {
return second;
}
}
class MultisetTree<T> {
int size = 0;
TreeMap<T, Integer> mp = new TreeMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
boolean contains(T x) {
return mp.containsKey(x);
}
T greatest() {
return mp.lastKey();
}
Integer keyCnt(T x) {
return mp.get(x);
}
T higher(T x) {
return mp.higherKey(x);
}
T smaller(T x) {
return mp.lowerKey(x);
}
T smaller2(T x) {
if (mp.containsKey(x)) {
return x;
}
return smaller(x);
}
T smallest() {
return mp.firstKey();
}
T biggest() {
return mp.lastKey();
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
class Multiset<T> {
int size = 0;
Map<T, Integer> mp = new HashMap<>();
void add(T x) {
mp.merge(x, 1, Integer::sum);
size++;
}
boolean contains(T x) {
return mp.containsKey(x);
}
void remove(T x) {
if (mp.containsKey(x)) {
mp.merge(x, -1, Integer::sum);
if (mp.get(x) == 0) {
mp.remove(x);
}
size--;
}
}
int size() {
return size;
}
int diffSize() {
return mp.size();
}
}
static class Range {
int l, r;
int id;
public int getL() {
return l;
}
public int getR() {
return r;
}
public Range(int l, int r, int id) {
this.l = l;
this.r = r;
this.id = id;
}
}
static class Array {
static Range[] readRanges(int n, FastScanner in) {
Range[] result = new Range[n];
for (int i = 0; i < n; i++) {
result[i] = new Range(in.nextInt(), in.nextInt(), i);
}
return result;
}
static List<List<Integer>> intInit2D(int n) {
List<List<Integer>> res = new ArrayList<>();
for (int i = 0; i < n; i++) {
res.add(new ArrayList<>());
}
return res;
}
static boolean isSorted(Integer[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static public long sum(List<Integer> a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static public long sum(int[] a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static public long sum(long[] a) {
long sum = 0;
for (long x : a) {
sum += x;
}
return sum;
}
static public long sum(Integer[] a) {
long sum = 0;
for (int x : a) {
sum += x;
}
return sum;
}
static public int min(Integer[] a) {
int mn = Integer.MAX_VALUE;
for (int x : a) {
mn = Math.min(mn, x);
}
return mn;
}
static public int min(int[] a) {
int mn = Integer.MAX_VALUE;
for (int x : a) {
mn = Math.min(mn, x);
}
return mn;
}
static public int max(Integer[] a) {
int mx = Integer.MIN_VALUE;
for (int x : a) {
mx = Math.max(mx, x);
}
return mx;
}
static public int max(int[] a) {
int mx = Integer.MIN_VALUE;
for (int x : a) {
mx = Math.max(mx, x);
}
return mx;
}
static public int[] readint(int n, FastScanner in) {
int[] out = new int[n];
for (int i = 0; i < out.length; i++) {
out[i] = in.nextInt();
}
return out;
}
}
class Graph {
List<List<Integer>> graph;
public List<Integer> edges;
Graph(int n) {
create(n);
}
private void create(int n) {
List<List<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
graph.add(new ArrayList<>());
}
this.graph = graph;
this.edges = new ArrayList<>();
}
int size() {
return graph.size();
}
List<Integer> abj(int v) {
return graph.get(v);
}
void read(int m, FastScanner in) {
for (int i = 0; i < m; i++) {
int v = in.nextInt() - 1;
int u = in.nextInt() - 1;
graph.get(v).add(u);
}
}
void readBi(int m, FastScanner in) {
for (int i = 0; i < m; i++) {
int v = in.nextInt() - 1;
int u = in.nextInt() - 1;
addEdge(v, u);
edges.add(v);
edges.add(u);
}
}
public void addEdge(int v, int u) {
graph.get(v).add(u);
graph.get(u).add(v);
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String line() {
String result = "";
try {
result = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public char[] nextc() {
return next().toCharArray();
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextInt();
}
return res;
}
public int[] nextArray() {
int n = in.nextInt();
return nextArray(n);
}
public long[] nextArrayL(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextLong();
}
return res;
}
public Long[] nextArrayL2(int n) {
Long[] res = new Long[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextLong();
}
return res;
}
public Integer[] nextArray2(int n) {
Integer[] res = new Integer[n];
for (int i = 0; i < n; i++) {
res[i] = in.nextInt();
}
return res;
}
public long nextLong() {
return Long.parseLong(next());
}
}
void run_t_tests() {
int t = in.nextInt();
int i = 0;
while (t-- > 0) {
solve(in, out, i++);
}
}
void run_one() {
solve(in, out, -1);
}
@Override
public void run() {
try {
in = new FastScanner(use_file_input_output ? new FileInputStream(input_file) : System.in);
out = new PrintWriter(use_file_input_output ? new FileOutputStream(output_file) : System.out);
if (use_n_tests) {
run_t_tests();
} else {
run_one();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static FastScanner in;
static PrintWriter out;
public static void main(String[] args) throws InterruptedException {
Thread thread = new Thread(null, new Main(), "", stack_size);
thread.start();
thread.join();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d4e0be4498ec746ab639e504658ca673 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class C {
static class RealScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
RealScanner sc = new RealScanner();
int t = sc.nextInt();
while (t-- > 0) {
long n, x;
n = sc.nextLong();
x = sc.nextLong() + 1;
long res = 0;
List<Long> l = new ArrayList<>();
for (long i = 0; i < n; i++) {
l.add(sc.nextLong());
}
BigInteger m = new BigInteger(String.valueOf(10));
for (long i = 0; i < n - 1; i++) {
if (x > 0) {
long val1 = (long) (Math.pow(10, l.get((int) (i + 1)) - l.get((int) i)) - 1);
long val2 = Math.min(x, val1);
res += val2 * Math.pow(10, l.get((int) i));
x = x - val2;
}
}
//long to BigInteger.. this is awesome by Java
BigInteger x1 = BigInteger.valueOf(x);
BigInteger b = BigInteger.valueOf(res);
BigInteger pow = BigInteger.valueOf(10);
//res += (x * Math.pow(10, l.get((int) (n - 1))));
b = b.add(x1.multiply(pow.pow(Math.toIntExact(l.get((int) (n - 1))))));
System.out.println(b);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 4626c9d599a1a7f6e4d1e6357a4fad88 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.*;
public class _116 {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
long [] pow = new long[19];
long start = 1;
for (int i = 0; i < 19; i++) {
pow[i] = start;
start *= 10;
}
while (t-- > 0) {
int n = sc.nextInt();
long k = sc.nextLong();
Set<Integer> set = new HashSet<>();
for (int i = 0; i < n; i++) set.add(sc.nextInt());
set.add(18);
ArrayDeque<Long> res = new ArrayDeque<>();
int cur = 0;
long moves = 0;
while (moves < k + 1) {
int s = cur;
cur++;
while (!set.contains(cur)) ++cur;
long p = pow[cur - s] - 1;
if (moves + p > k + 1) {
res.addFirst(k + 1 - moves);
moves = k + 1;
} else {
res.addFirst(p);
moves += p;
}
}
while (!res.isEmpty()) out.print(res.pollFirst());
out.println();
}
out.close();
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 790f28e6f7374bd9ab3f2d5a4d0907e9 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
// snippet
public class c {
// Question Link :
public static void main(String[] args) {
FastScanner sc=new FastScanner();
int T=sc.nextInt();
for (int tt=0; tt<T; tt++) {
int n = sc.nextInt();
long k = sc.nextLong();
k+=1;
long ans =0;
long arr[] = new long[n];
for (int i = 0; i < arr.length; i++) {
arr[i]= sc.nextLong();
}
for (int i = 0; i < arr.length-1; i++) {
if(k>0) {
long m = (long)Math.pow(10, arr[i+1]-arr[i])-1;
long x = Math.min(m, k);
ans+=(long)Math.pow(10, arr[i])*x;
k-=x;
}
}
ans+=k*(long)Math.pow(10,arr[n-1]);
System.out.println(ans);
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 54bf27c98233e0f7a83d48923b06e460 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Banknotes {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
String[] st = br.readLine().split(" ");
int n = Integer.parseInt(st[0]);
int k = Integer.parseInt(st[1]) + 1;
String[] str = br.readLine().split(" ");
int a[] = new int[n];
for(int i = 0; i < n; i++) {
a[i] = Integer.parseInt(str[i]);
int val = a[i];
a[i] = 1;
while(val-- > 0) {
a[i] = a[i]*10;
}
}
long res = 0;
for(int i = 0; i < n; i++) {
int cnt = k;
if(i+1 < n) cnt = Math.min(cnt, a[i+1]/a[i] - 1);
res += (long) a[i] * cnt;
k = k - cnt;
}
System.out.println(res);
}
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 1ca3d35ed025e1ea25be86c7a6cf90b2 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
import java.io.*;
public class Main{
static class pair{
int x ;int y ;
pair(int x ,int y )
{
this.x=x;
this.y =y;
}
}
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void prlong(Object object) throws IOException {
bw.append("" + object);
}
public void prlongln(Object object) throws IOException {
prlong(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long fun(long n, long x)
{
if(x>n)
return x;
n = n + x/2;
n = n - (n%x);
return n;
}
static int lower_bound(long[] array, long key, int low , int high)
{
// Initialize starting index and
// ending index
int mid;
while (low < high) {
mid = low + (high - low) / 2;
if (key <= array[mid]) {
high = mid;
}
else {
low = mid + 1;
}
}
if (low < array.length && array[low] < key) {
low++;
}
return low;
}
static int upper_bound(int arr[], int key,int low ,int high)
{
int mid, N = arr.length;
// Initialise starting index and
// ending index
// Till low is less than high
while (low < high && low != N) {
// Find the index of the middle element
mid = low + (high - low) / 2;
// If key is greater than or equal
// to arr[mid], then find in
// right subarray
if (key >= arr[mid]) {
low = mid + 1;
}
// If key is less than arr[mid]
// then find in left subarray
else {
high = mid;
}
}
// If key is greater than last element which is
// array[n-1] then upper bound
// does not exists in the array
if (low == N ) {
return -1;
}
return low;
}
static int help(int grid[][],int i,int j ,int n ,int dp[][])
{
if(i==2-1&&j==n-1)
return grid[i][j];
if(i>=2||j>=n)
return 100000;
if(dp[i][j]!=-1)
return dp[i][j];
int op1 =grid[i][j]+help(grid,i+1,j,n,dp);
int op2 =grid[i][j]+help(grid,i,j+1,n,dp);
if(op1<op2)
grid[i+1][j]=0;
else grid[i][j+1]=0;
return dp[i][j]=Math.min(op1,op2);
}
static int help1(int grid[][],int i,int j ,int n ,int dp[][])
{
if(i==2-1&&j==n-1)
return 0;
if(i>=2||j>=n)
return -1000000;
if(dp[i][j]!=-1)
return dp[i][j];
int op1 =grid[i][j]+help(grid,i+1,j,n,dp);
int op2 =grid[i][j]+help(grid,i,j+1,n,dp);
return dp[i][j]=Math.max(op1,op2);
}
static int ans ;
static void KMPSearch(String pat, String txt)
{
int M = pat.length();
int N = txt.length();
// create lps[] that will hold the longest
// prefix suffix values for pattern
int lps[] = new int[M];
int j = 0; // index for pat[]
// Preprocess the pattern (calculate lps[]
// array)
computeLPSArray(pat, M, lps);
int i = 0; // index for txt[]
while ((N - i) >= (M - j)) {
if (pat.charAt(j) == txt.charAt(i)) {
j++;
i++;
}
if (j == M) {
ans++;
j = lps[j - 1];
}
// mismatch after j matches
else if (i < N && pat.charAt(j) != txt.charAt(i)) {
// Do not match lps[0..lps[j-1]] characters,
// they will match anyway
if (j != 0)
j = lps[j - 1];
else
i = i + 1;
}
}
}
static void computeLPSArray(String pat, int M, int lps[])
{
int len = 0;
int i = 1;
lps[0] = 0; // lps[0] is always 0
// the loop calculates lps[i] for i = 1 to M-1
while (i < M) {
if (pat.charAt(i) == pat.charAt(len)) {
len++;
lps[i] = len;
i++;
}
else // (pat[i] != pat[len])
{
// This is tricky. Consider the example.
// AAACAAAA and i = 7. The idea is similar
// to search step.
if (len != 0) {
len = lps[len - 1];
// Also, note that we do not increment
// i here
}
else // if (len == 0)
{
lps[i] = len;
i++;
}
}
}
}
static int LIS(int v[])
{
if (v.length == 0) // boundary case
return 0;
int[] tail = new int[v.length];
int length = 1; // always points empty slot in tail
tail[0] = v[0];
for (int i = 1; i < v.length; i++) {
if (v[i] < tail[length - 1]) {
// v[i] extends the largest subsequence
tail[length++] = v[i];
}
else {
// v[i] will extend a subsequence and
// discard older subsequence
// find the largest value just smaller than
// v[i] in tail
// to find that value do binary search for
// the v[i] in the range from begin to 0 +
// length
int idx = Arrays.binarySearch(
tail, 0, length - 1, v[i]);
// binarySearch in java returns negative
// value if searched element is not found in
// array
// this negative value stores the
// appropriate place where the element is
// supposed to be stored
if (idx < 0)
idx = -1 * idx - 1;
// replacing the existing subsequence with
// new end value
tail[idx] = v[i];
}
}
return length;
}
static void printDistinctPermutn(String str,
String ans,ArrayList<Integer>arr )
{
// If string is empty
if (str.length() == 0) {
// print ans
arr.add(Integer.parseInt(ans));
return;
}
// Make a boolean array of size '26' which
// stores false by default and make true
// at the position which alphabet is being
// used
boolean alpha[] = new boolean[10];
for (int i = 0; i < str.length(); i++) {
// ith character of str
char ch = str.charAt(i);
// Rest of the string after excluding
// the ith character
String ros = str.substring(0, i) +
str.substring(i + 1);
// If the character has not been used
// then recursive call will take place.
// Otherwise, there will be no recursive
// call
if (alpha[ch - '0'] == false)
printDistinctPermutn(ros, ans + ch,arr);
alpha[ch - '0'] = true;
}
}
static int sumofdigits(long a)
{
String s =a+"";int sum =0;
for(int i =0;i<s.length();i++)
sum=sum+s.charAt(i)-'0';
return sum;
}
static long sum(long k,long brr[])
{
long ans=0;long arr[]=new long[brr.length];
for(long i =0;i<arr.length;i++)
{
arr[(int) i]=brr[(int) i]+(i+1)*k;
}
Arrays.sort(arr);
for (int i = 0; i < k; i++) {
ans=ans+arr[i];
}
return ans ;
}
public static void main(String[] args) {
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
long testCases=in.nextLong();
while(testCases-- > 0) {
int n = in.nextInt();
long arr[]=new long[n];
long k =in.nextInt()+1;
for (int i =0;i<n;i++) {
arr[i] = (long) Math.pow(10,in.nextInt());
}
Arrays.sort(arr);
long ans=0;
for(int i =0;i<n-1;i++)
{
long no =k;
no =Math.min(k ,(arr[i+1]-1)/arr[i]);
ans=ans+no*arr[i];
k=k-no;
if(k<0)
break;
}
if(k>0)
ans=ans+k*arr[n-1];
System.out.println(ans);
}
out.close();
} catch (Exception e) {
return;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d8497e2b75ef77ceb4abd46d6da04fba | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.io.*;
public class New {
public static long[] input(BufferedReader br,int n) throws java.lang.Exception{
String input[]=br.readLine().split(" ");
long out[]=new long[n];
for(int i=0;i<n;i++) {
out[i]=Long.parseLong(input[i]);
}
return out;
}
public static long find(long a, HashMap<Long,Long>map) {
String s=a+"";
long total=0;
int len=s.length();
for(int i=0;i<len;i++) {
long b=len-i-1;
total+=(s.charAt(i)-'0')*map.get(b);
}
return total;
}
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int testCases = Integer.parseInt(br.readLine());
// int testCases=1;
while(testCases-->0){
long input[]=input(br, 2);
long n=input[0];
long k=input[1]+1;
long arr[]=input(br,(int)n);
Arrays.sort(arr);
long res=0;
for(int i=0;i<n-1;i++) {
long a=(long)Math.pow(10, arr[i+1]);
long b=(long)Math.pow(10, arr[i]);
long val=a/b-1;
val=Math.min(k, val);
res+=val*b;
k-=val;
}
res+=k*(long)Math.pow(10,arr[(int)n-1]);
out.println(res);
}
out.close();
}
}
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | 20114920e0f0d17a6335e6e30b1b8524 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static final PrintWriter out =new PrintWriter(System.out);
static final FastReader sc = new FastReader();
//I invented a new word!Plagiarism!
//Did you hear about the mathematician who’s afraid of negative numbers?He’ll stop at nothing to avoid them
//What do Alexander the Great and Winnie the Pooh have in common? Same middle name.
//I finally decided to sell my vacuum cleaner. All it was doing was gathering dust!
//ArrayList<Integer> a=new ArrayList <Integer>();
//PriorityQueue<Integer> pq=new PriorityQueue<>();
//char[] a = s.toCharArray();
// char s[]=sc.next().toCharArray();
public static boolean sorted(int a[])
{
int n=a.length,i;
int b[]=new int[n];
for(i=0;i<n;i++)
b[i]=a[i];
Arrays.sort(b);
for(i=0;i<n;i++)
{
if(a[i]!=b[i])
return false;
}
return true;
}
public static void main (String[] args) throws java.lang.Exception
{
int tes=sc.nextInt();
label:while(tes-->0)
{
int n=sc.nextInt();
long k=sc.nextLong();
long a[]=new long[n];
int i;
long ans=0;
for(i=0;i<n;i++)
{
long x=sc.nextLong();
a[i]=(long)Math.pow(10,x);
}
if(n==1)
{
System.out.println(k+1);
continue;
}
k++;
for(i=0;i<n-1;i++)
{
long x=a[i+1]/a[i];
x--;
if(x>=k)
{
ans+=k*a[i];
System.out.println(ans);
continue label;
}
ans+=x*a[i];
k-=x;
}
if(k!=0)
ans+=k*a[n-1];
System.out.println(ans);
}
}
public static int first(ArrayList<Integer> arr, int low, int high, int x, int n)
{
if (high >= low) {
int mid = low + (high - low) / 2;
if ((mid == 0 || x > arr.get(mid-1)) && arr.get(mid) == x)
return mid;
else if (x > arr.get(mid))
return first(arr, (mid + 1), high, x, n);
else
return first(arr, low, (mid - 1), x, n);
}
return -1;
}
public static int last(ArrayList<Integer> arr, int low, int high, int x, int n)
{
if (high >= low) {
int mid = low + (high - low) / 2;
if ((mid == n - 1 || x < arr.get(mid+1)) && arr.get(mid) == x)
return mid;
else if (x < arr.get(mid))
return last(arr, low, (mid - 1), x, n);
else
return last(arr, (mid + 1), high, x, n);
}
return -1;
}
public static int lis(int[] arr) {
int n = arr.length;
ArrayList<Integer> al = new ArrayList<Integer>();
al.add(arr[0]);
for(int i = 1 ; i<n;i++) {
int x = al.get(al.size()-1);
if(arr[i]>=x) {
al.add(arr[i]);
}else {
int v = upper_bound(al, 0, al.size(), arr[i]);
al.set(v, arr[i]);
}
}
return al.size();
}
public static int lower_bound(ArrayList<Long> ar,int lo , int hi , long k)
{
Collections.sort(ar);
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get((int)mid) <k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}
public static int upper_bound(ArrayList<Integer> ar,int lo , int hi, int k)
{
Collections.sort(ar);
int s=lo;
int e=hi;
while (s !=e)
{
int mid = s+e>>1;
if (ar.get(mid) <=k)
{
s=mid+1;
}
else
{
e=mid;
}
}
if(s==ar.size())
{
return -1;
}
return s;
}
static boolean isPrime(long N)
{
if (N<=1) return false;
if (N<=3) return true;
if (N%2 == 0 || N%3 == 0) return false;
for (int i=5; i*i<=N; i=i+6)
if (N%i == 0 || N%(i+2) == 0)
return false;
return true;
}
static int countBits(long a)
{
return (int)(Math.log(a)/Math.log(2)+1);
}
static long fact(long N)
{
long mod=1000000007;
long n=2;
if(N<=1)return 1;
else
{
for(int i=3; i<=N; i++)n=(n*i)%mod;
}
return n;
}
private static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
} catch (NullPointerException e) {
return false;
}
return true;
}
private static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
private static boolean isPalindrome(String str) {
int i = 0, j = str.length() - 1;
while (i < j)
if (str.charAt(i++) != str.charAt(j--))
return false;
return true;
}
private static String reverseString(String str) {
StringBuilder sb = new StringBuilder(str);
return sb.reverse().toString();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | d20d68ab69fdefc52e179918957c8d04 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import java.util.*;
import java.io.*;
import java.math.*;
public class C_Banknotes {
static long mod = Long.MAX_VALUE;
public static void main(String[] args) {
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
FastReader f = new FastReader();
int t = f.nextInt();
while(t-- > 0){
solve(f, out);
}
out.close();
}
public static void solve(FastReader f, PrintWriter out) {
int n = f.nextInt();
int k = f.nextInt();
k++;
int arr[] = f.nextArray(n);
for(int i = 0; i < n; i++) {
arr[i] = (int)power(10, arr[i]);
}
long ans = 0;
for(int i = 0; i < n-1; i++) {
int count = arr[i+1]/arr[i] - 1;
count = min(count, k);
k -= count;
ans += (long)count*arr[i];
if(k <= 0) {
break;
}
}
ans += (long)k*arr[n-1];
out.println(ans);
}
// Sort an array
public static void sort(int arr[]) {
ArrayList<Integer> al = new ArrayList<>();
for(int i: arr) {
al.add(i);
}
Collections.sort(al);
for(int i = 0; i < arr.length; i++) {
arr[i] = al.get(i);
}
}
// Find all divisors of n
public static void allDivisors(int n) {
for(int i = 1; i*i <= n; i++) {
if(n%i == 0) {
System.out.println(i + " ");
if(i != n/i) {
System.out.println(n/i + " ");
}
}
}
}
// Check if n is prime or not
public static boolean isPrime(int n) {
if(n < 1) return false;
if(n == 2 || n == 3) return true;
if(n % 2 == 0 || n % 3 == 0) return false;
for(int i = 5; i*i <= n; i += 6) {
if(n % i == 0 || n % (i+2) == 0) {
return false;
}
}
return true;
}
// Find gcd of a and b
public static long gcd(long a, long b) {
long dividend = a > b ? a : b;
long divisor = a < b ? a : b;
while(divisor > 0) {
long reminder = dividend % divisor;
dividend = divisor;
divisor = reminder;
}
return dividend;
}
// Find lcm of a and b
public static long lcm(long a, long b) {
long lcm = gcd(a, b);
long hcf = (a * b) / lcm;
return hcf;
}
// Find factorial in O(n) time
public static long fact(int n) {
long res = 1;
for(int i = 2; i <= n; i++) {
res *= res * i;
}
return res;
}
// Find power in O(logb) time
public static long power(long a, long b) {
long res = 1;
while(b > 0) {
if((b&1) == 1) {
res = (res * a)%mod;
}
a = (a * a)%mod;
b >>= 1;
}
return res;
}
// Find nCr
public static long nCr(int n, int r) {
if(r < 0 || r > n) {
return 0;
}
long ans = fact(n) / (fact(r) * fact(n-r));
return ans;
}
// Find nPr
public static long nPr(int n, int r) {
if(r < 0 || r > n) {
return 0;
}
long ans = fact(n) / fact(r);
return ans;
}
// sort all characters of a string
public static String sortString(String inputString) {
char tempArray[] = inputString.toCharArray();
Arrays.sort(tempArray);
return new String(tempArray);
}
// User defined class for fast I/O
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
boolean hasNext() {
if (st != null && st.hasMoreTokens()) {
return true;
}
String tmp;
try {
br.mark(1000);
tmp = br.readLine();
if (tmp == null) {
return false;
}
br.reset();
} catch (IOException e) {
return false;
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
boolean nextBoolean() {
return Boolean.parseBoolean(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextArray(int n) {
int[] a = new int[n];
for(int i=0; i<n; i++) {
a[i] = nextInt();
}
return a;
}
}
}
/**
Dec Char Dec Char Dec Char Dec Char
--------- --------- --------- ----------
0 NUL (null) 32 SPACE 64 @ 96 `
1 SOH (start of heading) 33 ! 65 A 97 a
2 STX (start of text) 34 " 66 B 98 b
3 ETX (end of text) 35 # 67 C 99 c
4 EOT (end of transmission) 36 $ 68 D 100 d
5 ENQ (enquiry) 37 % 69 E 101 e
6 ACK (acknowledge) 38 & 70 F 102 f
7 BEL (bell) 39 ' 71 G 103 g
8 BS (backspace) 40 ( 72 H 104 h
9 TAB (horizontal tab) 41 ) 73 I 105 i
10 LF (NL line feed, new line) 42 * 74 J 106 j
11 VT (vertical tab) 43 + 75 K 107 k
12 FF (NP form feed, new page) 44 , 76 L 108 l
13 CR (carriage return) 45 - 77 M 109 m
14 SO (shift out) 46 . 78 N 110 n
15 SI (shift in) 47 / 79 O 111 o
16 DLE (data link escape) 48 0 80 P 112 p
17 DC1 (device control 1) 49 1 81 Q 113 q
18 DC2 (device control 2) 50 2 82 R 114 r
19 DC3 (device control 3) 51 3 83 S 115 s
20 DC4 (device control 4) 52 4 84 T 116 t
21 NAK (negative acknowledge) 53 5 85 U 117 u
22 SYN (synchronous idle) 54 6 86 V 118 v
23 ETB (end of trans. block) 55 7 87 W 119 w
24 CAN (cancel) 56 8 88 X 120 x
25 EM (end of medium) 57 9 89 Y 121 y
26 SUB (substitute) 58 : 90 Z 122 z
27 ESC (escape) 59 ; 91 [ 123 {
28 FS (file separator) 60 < 92 \ 124 |
29 GS (group separator) 61 = 93 ] 125 }
30 RS (record separator) 62 > 94 ^ 126 ~
31 US (unit separator) 63 ? 95 _ 127 DEL
*/
// (a/b)%mod == (a * moduloInverse(b)) % mod;
// moduloInverse(b) = power(b, mod-2);
| Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | fd6bcec950ec71edb80879033622c463 | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class C {
static long dfs(int source, int parent, long x, ArrayList<ArrayList<Integer>> adj, long[] arr) {
long s = arr[source];
for (Integer i : adj.get(source)) {
if (i != parent) {
s += dfs(i, source, x, adj, arr);
}
}
return Math.max(s, -x);
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long gcd(long n, long m) {
if (m == 0)
return n;
return gcd(m, n % m);
}
static long lcm(long n, long m) {
return (n * m) / gcd(n, m);
}
static class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
static long modexpo(long x, long n, long m) {
if (n == 0)
return 1 % m;
long u = modexpo(x, n / 2, m);
u = (u * u) % m;
if (n % 2 == 1)
u = (u * x) % m;
return u;
}
static StringBuilder str = new StringBuilder();
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
long[] pow = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
for (int xx = 0; xx < t; xx++) {
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
long s = 0;
k++;
for (int i = 0; i < n - 1; i++) {
if (k == 0)
break;
long d = pow[arr[i + 1]] - pow[arr[i]];
long c = d / pow[arr[i]];
if (c > k) {
c = k;
}
d = c * pow[arr[i]];
s += d;
k = k - (int) c;
}
if (k >= 1)
s += pow[arr[n - 1]] * k;
str.append(s);
str.append("\n");
}
System.out.println(str);
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output | |
PASSED | ca12ea72d5f97fb1b06a205889547e8b | train_108.jsonl | 1635518100 | In Berland, $$$n$$$ different types of banknotes are used. Banknotes of the $$$i$$$-th type have denomination $$$10^{a_i}$$$ burles (burles are the currency used in Berland); the denomination of banknotes of the first type is exactly $$$1$$$.Let's denote $$$f(s)$$$ as the minimum number of banknotes required to represent exactly $$$s$$$ burles. For example, if the denominations of banknotes used in Berland are $$$1$$$, $$$10$$$ and $$$100$$$, then $$$f(59) = 14$$$: $$$9$$$ banknotes with denomination of $$$1$$$ burle and $$$5$$$ banknotes with denomination of $$$10$$$ burles can be used to represent exactly $$$9 \cdot 1 + 5 \cdot 10 = 59$$$ burles, and there's no way to do it with fewer banknotes.For a given integer $$$k$$$, find the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes (that is, $$$f(s) > k$$$). | 256 megabytes | import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class C_Banknotes {
public static void s() {
int n = sc.nextInt();
int k = sc.nextInt();
k++;
long[] arr = sc.readLongArray(n);
for(int i=0; i<arr.length; i++) {
arr[i] = (int)Math.pow(10, arr[i]);
}
long[] value = new long[n];
for(int i=0; i<n-1; i++) {
value[i] = arr[i+1]/arr[i] - 1;
}
value[n-1] = Long.MAX_VALUE;
long ans = 0;
for(int i=0; i<value.length; i++) {
long use = Functions.min(k, value[i]);
k-=use;
ans += use*arr[i];
}
p.writeln(ans);
}
public static void main(String[] args) {
int t = 1;
t = sc.nextInt();
while (t-- != 0) {
s();
}
p.print();
}
public static boolean debug = false;
static void debug(String st) {
if(debug) p.writeln(st);
}
static final Integer MOD = (int) 1e9 + 7;
static final FastReader sc = new FastReader();
static final Print p = new Print();
static class Functions {
static void sort(int... a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
static void sort(long... a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++) a[i] = l.get(i);
}
static int max(int... a) {
int max = Integer.MIN_VALUE;
for (int val : a) max = Math.max(val, max);
return max;
}
static int min(int... a) {
int min = Integer.MAX_VALUE;
for (int val : a) min = Math.min(val, min);
return min;
}
static long min(long... a) {
long min = Long.MAX_VALUE;
for (long val : a) min = Math.min(val, min);
return min;
}
static long max(long... a) {
long max = Long.MIN_VALUE;
for (long val : a) max = Math.max(val, max);
return max;
}
static long sum(long... a) {
long sum = 0;
for (long val : a) sum += val;
return sum;
}
static int sum(int... a) {
int sum = 0;
for (int val : a) sum += val;
return sum;
}
public static long mod_add(long a, long b) {
return (a % MOD + b % MOD + MOD) % MOD;
}
public static long pow(long a, long b) {
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = mod_mul(res, a);
a = mod_mul(a, a);
b >>= 1;
}
return res;
}
public static long mod_mul(long a, long b) {
long res = 0;
a %= MOD;
while (b > 0) {
if ((b & 1) > 0) {
res = mod_add(res, a);
}
a = (2 * a) % MOD;
b >>= 1;
}
return res;
}
public static long gcd(long a, long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
public static long factorial(long n) {
long res = 1;
for (int i = 1; i <= n; i++) {
res = (i % MOD * res % MOD) % MOD;
}
return res;
}
public static int count(int[] arr, int x) {
int count = 0;
for (int val : arr) if (val == x) count++;
return count;
}
public static ArrayList<Integer> generatePrimes(int n) {
boolean[] primes = new boolean[n];
for (int i = 2; i < primes.length; i++) primes[i] = true;
for (int i = 2; i < primes.length; i++) {
if (primes[i]) {
for (int j = i * i; j < primes.length; j += i) {
primes[j] = false;
}
}
}
ArrayList<Integer> arr = new ArrayList<>();
for (int i = 0; i < primes.length; i++) {
if (primes[i]) arr.add(i);
}
return arr;
}
}
static class Print {
StringBuffer strb = new StringBuffer();
public void write(Object str) {
strb.append(str);
}
public void writes(Object str) {
char c = ' ';
strb.append(str).append(c);
}
public void writeln(Object str) {
char c = '\n';
strb.append(str).append(c);
}
public void writeln() {
char c = '\n';
strb.append(c);
}
public void yes() {
char c = '\n';
writeln("YES");
}
public void no() {
writeln("NO");
}
public void writes(int... arr) {
for (int val : arr) {
write(val);
write(' ');
}
}
public void writes(long... arr) {
for (long val : arr) {
write(val);
write(' ');
}
}
public void writeln(int... arr) {
for (int val : arr) {
writeln(val);
}
}
public void print() {
System.out.print(strb);
}
public void println() {
System.out.println(strb);
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
double[] readArrayDouble(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
String nextLine() {
String str = new String();
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["4\n3 13\n0 1 2\n2 777\n0 4\n3 255\n0 1 3\n10 1000000000\n0 1 2 3 4 5 6 7 8 9"] | 2 seconds | ["59\n778\n148999\n999999920999999999"] | null | Java 11 | standard input | [
"greedy",
"number theory"
] | e25e44b8f300d6be856df50bff8ff244 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10; 1 \le k \le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 = a_1 < a_2 < \dots < a_n \le 9$$$). | 1,400 | For each test case, print one integer — the minimum positive number of burles $$$s$$$ that cannot be represented with $$$k$$$ or fewer banknotes. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.