M
the sum must be maximum, so choosing the largest in the last will increase the sum value
M
but its not true for all case eg n=4,k=2 arr=1,2,3,4 here answer is 10 how? 4+3(*2)
M
yes
aklil
yes
then the pattern i see is, newarr = [arr[0]*(k+1), arr[1]*(k+1), arr[2]*(k+1).....arr[n-k]*(k+1)]; sum = arr[n-1] + arr[n-2]*2 + arr[n-3]*2....arr[n-k]*2 + max(newarr)
M
No it can be in any order ,there is no pattern in it ,thats why i used recursion to find all possible ways and then find the max out of it
Never Spam Bot
@Amadaclaire sent multiple messages that looks like a spam. If they send more spam - like messages, they will be muted. Only admins can unmute them. Spam deleted in this group: 118 See spam? Quote it and send /spam
Manav
It's obvious that a variable of type int will be a number
Manav
I'll give you an example, if i am given three numbers: a, b and c. This would be how i would start thinking about a possible algorithm: check a > b check b > c check c > a | a>b | b>c | c>a |r| | T | T | T |not possible| | F | T | T |b>c>a| | T | F | T |c>a>b| | T | T | F |a>b>c| ... do the rest..
Zidane
Okay thats my mistake but i changed like number1 > number2 && number1 > number3 and it didnt work again
Zidane
I thinked first i need the choose max number and when code found the max number, enter into the condition and keep going from there
Manav
don't jump into coding things
Zidane
I know the solve
Manav
I know the solve
you don't
Manav
you're checking first three numbers and then there's many cases you are ignoring
Manav
do the bruteforce method, by checking all numbers
Manav
for 5 numbers the comparision amount would be 32 which you can easily do it on pape
Zidane
this is a mess tbh
Actually it is not comlicated in code page i can send the photo
Manav
Actually it is not comlicated in code page i can send the photo
Photo doesn't help. I copy pasted your code and tried it out.
Zidane
Okey
Manav
The naming also doesn't help either
Zidane
why
Zidane
for these
Zidane
printf("arrangement of numbers: %d>%d>%d",max,middle,min);
Zidane
ı think the problem is not in the naming
Manav
Why store middle in number2?
Manav
It makes no sense to touch number2 or number
Manav
number1>number2 && number2>number3 this is probably what you were thinking which makes number1 > number2 > number3
Manav
so max is number1, okay you do that
Manav
But the if checks later make no sense
Zidane
ok it could be work with 6 obtion
Zidane
but ı dont my code is not working
Zidane
understand
Manav
but ı dont my code is not working
Because you have no idea what your code does
Manav
It's simple really, you only to check between these three number1 and number2 number2 and number3 number3 and number1
Manav
Then proceed, this is thr bruteforce method, you just do all comparisions before hand since it's just three numbers
Zidane
How does it make sense? First, I determine the largest number, then I compare the other two numbers, then I sort them
Zidane
if(number1>number2 && number1>number3){ max=number1; if(number2>number3){ number2=middle; number3=min; } if(number3>number2){ number2=min; number3=middle;} } else if(number2>number1 && number2>number3){ max=number2; if(number3>number1){ number3=middle; number1=min;} else if(number1>number3){ number3=min; number1=middle;}} else{ max=number3; if(number2>number1){ number2=middle; number1=min; } if(number1>number2){ number1=middle; number2=min;}}
Zidane
there is a three condition
Zidane
no ı check this in third condition
Manav
telegram now supports formatting properly, you'd want to take a look at the features
Manav
no ı check this in third condition
that check is not necessary
Zidane
if number3 greater than number2 first condisiton is not work
Zidane
third is going to work
Manav
no ı check this in third condition
Alright lemme ask you a question then
Zidane
else if (number3 > number1 && number3 > number2 if its true
Manav
Because you know number3 is the greatest since you checked already
Zidane
okay let me try this
Manav
okay let me try this
I feel like i confused you more than you already are.
Zidane
I feel like i confused you more than you already are.
Nooo thank you so much thank for time
Zidane
I need to try more
Manav
I's suggest you practice more about if else, you seem a bit confused about it.
Zidane
Yeah i will
Manav
Your program works now right?
Zidane
No :(
Zidane
It didnt work
Manav
No :(
Hmm, share the error, it should work.
Manav
and share your code properly, use telegram formatting or use a pastebin
Zidane
Program is working but the arrengment is not true