You are not logged in. Please login at to post your questions!


WA :Maximize It

Problem :

My Solution :

Working well with most of my Testcases ; Please help !

asked 24 Nov '18, 22:39

prembharwani's gravatar image

accept rate: 0%

It does not work for the following simple test case:

5 2
1 1 3 3 8
Your code generates 3, while it should be 4.

The code has multitude of problems, starting with

        int n,k;
        char numbers[n+1];
        int sum=0,sum1=0,prod=1,fprod=1,res=0,p;
        for(int i=0;i<n;i++){
            int num=1;
            for(int j=0;j<p;j++) {
1. You define array numbers[n+1] at the moment when n is not properly initialized yet. 2. You store values of powers of p in char which is limited by 127.

What's the most interesting is that your code is still able to solve some of the test cases.


answered 24 Nov '18, 23:54

oleg_b's gravatar image

accept rate: 18%

edited 24 Nov '18, 23:55

@oleg_b Thank You ! Even 'long long int' won't work for storing the values of the (integer)^(power) , Please correct me if I am wrong ?

(25 Nov '18, 07:14) prembharwani2★

Yes, 'long long int' does not have sufficient capacity. The approach should be quite different - you need to represent the numbers in the base of k. For example, if k is 10, then 10^100 is a vector with 101 elements, all of them are zeros, except the last one which is 1.

(25 Nov '18, 17:24) oleg_b7★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 24 Nov '18, 22:39

question was seen: 218 times

last updated: 25 Nov '18, 17:25