304 North Cardinal St.
Dorchester Center, MA 02124

# The One On The Last Night CodeChef Solution

## The One On The Last Night CodeChef Solution in C++17

``````#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
int T;
cin>>T;

while(T--)
{
int N, K;
vector<int> digits (0);
cin>>N>>K;
while(N>0)
{
digits.push_back(N%10);
N/=10;
}
sort(digits.begin(),digits.end());

int size=digits.size();
while(K--)
{
if(digits.at(0)==9)
{
break;
}
else
{
digits.at(0)+=1;
}
if(size>1)
{
if(digits.at(0)>digits.at(1))
{
sort(digits.begin(),digits.end());
}
}

}
int value {1};
for(auto &d:digits)
{
value*=d;
}

cout<<value<<endl;
}
}``````

## The One On The Last Night CodeChef Solution in C++14

``````#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);

ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;

vector<ll> v;
while(n>0)
{
v.push_back(n%10);
n/=10;
}

for(int i=0;i<k;i++)
{
sort(v.begin(),v.end());
if(v[0]==9)
break;

v[0]++;
}

ll p=1;
for(auto &e:v)
p*=e;

cout<<p<<endl;
}
}``````

## The One On The Last Night CodeChef Solution in PYTH 3

``````for _ in range(int(input())):
n,k=map(int,input().split())
l=[]
while n!=0:
r=n%10
n=n//10
l.append(r)
for i in range(k):
m=min(l)
if m==9:
break
l[l.index(m)]+=1
s=1
for j in l:
s*=j
print(s)``````

## The One On The Last Night CodeChef Solution in C

``````#include <stdio.h>

int main(void) {
int t;
scanf("%d",&t);
while(t--)
{
int n,k,r;
scanf("%d %d",&n,&k);
r=n;
int min=0,max=0; int i=0; int c=0; int y=0; int flag=1;
while(n!=0)
{
int d=n%10;
c++;
if(d>max)
max=d;
n/=10;
}
int a[c];
min=max;
while(r!=0)
{
int d=r%10;
a[i]=d;
r/=10;
i++;
}
if(k==0)
{
for( int i=0; i<c;i++)
{
flag*=a[i];
}
printf("%d\n",flag);
}
else
{
while(k!=0)
{
for( int i=0; i<c; i++)
{
if(a[i]<min)
{
min=a[i];
y=i;
}

}
if(min==9)
break;
min+=1;
a[y]=min;
k--;
}
for( int i=0; i<c;i++)
{
flag*=a[i];
}
printf("%d\n",flag);
}

}
return 0;
}
``````

## The One On The Last Night CodeChef Solution in JAVA

``````/* 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. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
{
if(sc.hasNext())
{
int t=sc.nextInt();
// List<String> output=new ArrayList<>();
for(int i=0;i<t;i++)
{
int n=sc.nextInt();
int k=sc.nextInt();
Queue<Integer> pq=new PriorityQueue<>();
int dummy=n;
while(dummy>0){
pq.offer(dummy%10);
dummy/=10;
}
long res=1;
while(k-->0){
if(pq.peek()<9)
pq.offer(pq.poll()+1);

}
while(!pq.isEmpty()){
res=res*(pq.poll());
}

System.out.println(res);
}
}
}

}
}``````

## The One On The Last Night CodeChef Solution in PYPY 3

``````from sys import stdin, stdout
for i in range(T):
N = list(map(int, list(str(N))))
M = sorted(N)
while(K!=0):
if M[0]==9:
break
else:

M[0]+=1
if 1<len(M):
if M[1]<M[0]:
M.sort()
else:
pass
K-=1
multiplication = 1
for j in M:
multiplication*=j
stdout.write(f"{multiplication}\n")

``````

## The One On The Last Night CodeChef Solution in PYTH

``````t = int(raw_input())
for i in range(t):
st = raw_input().split()
N = int(st[0])
K = int(st[1])
L = [0 for x in range(10)]
while N > 0:
d = N%10
N = N/10
L[d] += 1
# endwhile
p = 0
while (K > 0) and (p < 9):
n = min(K,L[p])
L[p] -= n
L[p+1] += n
K -= n
p += 1
# endwhile
r = 1
for p in range(10):
n = L[p]
if n > 0:
r = r*p**n
# endif
# endfor p
print r
# endfor i
``````

## The One On The Last Night CodeChef Solution in C#

``````#region usings
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections;
using static System.Math;
using static System.Array;
using static System.Convert;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#endregion
namespace CodeChef
{
public class Solution
{
private static readonly Scanner sc = new Scanner();
static void Main()
{
while (testCases-- > 0)
{
Solve(nk);
}
sc.Flush();
sc.Close();
}

private static void Solve(long[] nk)
{
long n = nk[0], k = nk[1];
List<long> digits = new List<long>();
while (n > 0)
{
n = n / 10;
}
int i = 0;
while (i < k)
{
var m = digits.Min();
if (m == 9)
break;
else
{
var a = digits.IndexOf(m);
digits[a] = m + 1;
i += 1;
}
}
sc.WriteLine(digits.Aggregate((item, next) => item * next));
}
}
public class Scanner
{

#if (!DEBUG)
public static StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput());
#else
public static StreamWriter streamWriter = new StreamWriter(@"c:\users\869963\source\repos\competitive\Codechef\TextFile2.txt");
#endif
#region Input
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
int[][] res = new int[n][];
for (int i = 0; i < n; i++)
{
}
return res;
}

#endregion
#region Output
public void Write<T>(T t)
{
streamWriter.Write(t);
}
public void WriteLine<T>(T result)
{
streamWriter.WriteLine(result);
}
public void WriteArray<T>(T[] secondHalf)
{
for (int i = 0; i < secondHalf.Length; i++)
{
streamWriter.WriteLine(secondHalf[i] + " ");
}
WriteLine("");
}
public void Write2DMatrix<T>(T[][] sum)
{
for (int i = 0; i < sum.Length; i++)
{
for (int j = 0; j < sum[i].Length; j++)
{
Write<string>(\$"{sum[i][j]}");
}
WriteLine<string>("");
}
}
public void YESNO(bool condition)
{
WriteLine(condition ? "YES" : "NO");
}
public void YesNo(bool condition)
{
WriteLine(condition ? "Yes" : "No");
}
public void yesno(bool condition)
{
WriteLine(condition ? "yes" : "no");
}
public void Flush()
{
streamWriter.Flush();
}
public void Close()
{
streamWriter.Close();
}

#endregion
}
public class Utilities
{
public static long PowerModular(long x, long y)
{
long res = 1;

while (y > 0)
{
if ((y & 1) != 0)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
public static T MostFrequent<T>(IEnumerable<T> source)
{
T res = source.GroupBy(auto => auto).OrderByDescending(g => g.Count()).First().Key;
return res;
}
public static long NearestPrime(long n)
{
if (n % 2 != 0)
n -= 2;
else
n--;

int i, j;
for (i = (int)n; i >= 2; i -= 2)
{
if (i % 2 == 0)
continue;
for (j = 3; j <= Math.Sqrt(i); j += 2)
{
if (i % j == 0)
break;
}
if (j > Math.Sqrt(i))
return i;
}
return 2;
}
public static long GCD(long a, long b)
{
if (b == 0)
return a;
return GCD(b, a % b);
}
public static long LCM(long a, long b)
{
return (a / GCD(a, b)) * b;
}
public static long[] SieveOfEratosthenes(int n)
{
bool[] prime = new bool[n + 1];
long j = 0; long[] arr = new long[n];
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 += p)
prime[i] = false;
}
}
for (int i = 2; i <= n; i++)
{
if (prime[i] == true)
{
arr[j] = i;
j++;
}
}
return arr;
}
}
}``````

## The One On The Last Night CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"container/heap"
"fmt"
"os"
"sort"
)

func main() {

var buf bytes.Buffer

for tc > 0 {
tc--

res := solve(n, m)
buf.WriteString(fmt.Sprintf("%d\n", res))
}
fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func solve(n int, k int) int64 {
var arr []int
for n > 0 {
arr = append(arr, n%10)
n /= 10
}
sort.Ints(arr)
//first make 0 to 1 possible
for i := 0; i < len(arr) && k > 0; i++ {
if arr[i] == 0 {
arr[i]++
k--
}
}
// if a < b, (a + 1) * b > a * (b + 1)
if k == 0 {
return product(arr)
}

// arr[i] <= 9, len(arr) < 10
pq := IntHeap(arr)
heap.Init(&pq)

for k > 0 && pq[0] < 9 {
cur := heap.Pop(&pq).(int)
cur++
heap.Push(&pq, cur)
k--
}

return product(arr)
}

func min(a, b int) int {
if a <= b {
return a
}
return b
}

func product(arr []int) int64 {
var res int64 = 1
for _, num := range arr {
res *= int64(num)
}

return res
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
// Push and Pop use pointer receivers because they modify the slice's length,
// not just its contents.
*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
old := *h
n := len(old)
x := old[n-1]
*h = old[0 : n-1]
return x
}``````
##### The One On The Last Night CodeChef Solution Review:

In our experience, we suggest you solve this The One On The Last Night CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the The One On The Last Night CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this The One On The Last Night CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!