Birthday Candles - CANDLE

Please help me with my code, I am getting wrong answer. Please tell me some cases where my code fails and suggest ways to improve it.

//My Code

#include <stdlib.h>
#include <stdio.h>
#include

using namespace std;

int min_positive(int *a, int size_a){
int m = 9, index;
for(int i = 1; i<size_a; i++){
if(m>a[i]){
m = a[i];
index = i;
}
}
return index;
}

int min_all(int *a, int size_a){
int m = 9, index;
for(int i = 0; i<size_a; i++){
if(m>a[i]){
m = a[i];
index = i;
}
}
return index;
}

int main(){

int t;
cin >> t;
while(t--){
    int *a = new int[10];
    for(int i = 0; i<10; i++){
        cin >> a[i];
    }
    int m,n;
    m = min_positive(a,10);
    if(a[m]==0){
        cout << m << endl;
    }
    else{
        a[m]--;
        n = min_all(a,10);
        m = m*10;
        while(a[n]!=0){
            m += n;
            a[n]--;
            n = min_all(a,10);
            m *= 10;
        }
        cout << m+n << endl;
    }
}
return 0;

}

in the function min_positive , in the for loop i think u should initiate i with 0 and not 1

i dont really understand what exactly you are trying to achieve though .Can you explain what you want to get as output ?

http://ideone.com/IJBjZO i am getting wrong answer for this question. i have tested my code over 20 test cases and its giving correct answer. Can anyone check and give some test cases on which my program is giving wrong answer?

1 Like

check this : 2 7 7 7 7 7 7 7 7 3

Your code gives 9000 as output while clearly the answer is 1000.

1 Like

I am giving the idea @archit910 , @abhishek010594 .Check whether this is what you are doing?
Now firstly zero is not a valid age. So if the digit 0 has zero frequency the minimum age that cannot be expressed is not 0. However if 1 or 2 or any other digit has the frequency 0, the minimum age that cannot be expressed is 1 or 2 or any of those digit.
Now if this is the input:
1 0 0 0 0 0 0 0 0 0
then the minimum age that cannot be expressed is 1. Now if the input is:
2 1 1 1 1 1 1 1 1 1
then the minimum age that cannot be expressed is 11.
So this is what you should do. Find the minimum frequency. If the minimum frequency is of a digit which is not zero, print that digit, minimum frequency times+1. If there are many digits with the minimum frequency print the minimum most digit.
If the digit zero has minimum frequency then print 1 and 0s minimum frequency+1 times.
So if the input is: 0 1 1 1 1 1 1 1 1 1
the output is 10 and if the input is : 1 2 2 2 2 2 2 2 2 2 then the output is 100. However if the input is 1 1 2 2 2 2 2 2 2 2 the answer is 11. That is why first check whether the minimum frequency is the frequency of any other digit other than 0.

@archit910 You may like to go through my solution :smiley:

https://www.codechef.com/viewsolution/7429820

1 Like