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

×

EXOCODE4 - Editorial

Problem Link:https://www.codechef.com/problems/EXOCODE4

Author:https://www.codechef.com/users/vivek96

DIFFICULTY:CakeWalk

PREREQUISITES:Basic Programming,Array

PROBLEM:Chef Purchased an array A having N Integer values,After Playing it for while,he got bored of it and decided to update value of its element.In one second he can increase value of each array element by 1.He wants each array element’s value to become greater than or equal to K.

Please Help Chef to find out the minimum amount of time it will take,for him to do so..

EXPLANATION:Since we can only increase all the elements by 1, the minimum element will take most step to reach K.So we have to find the minimum element in array A and answer will difference between K and minimum element.

One corner case is if K is less than minimum element in the array A

Time Complexity:O(N)

AUTHOR'S AND TESTER'S SOLUTIONS:

alt text

Note: We can also use Sorting(Bubble,Quick,etc) to find minimum element in Array, but this will increase time complexity

asked 15 Mar '17, 19:03

vivek96's gravatar image

2★vivek96
533221
accept rate: 8%

edited 20 Mar '17, 12:37

admin's gravatar image

0★admin ♦♦
19.8k350498541


Nice algorithm

link

answered 18 Mar '17, 22:26

sharma_akki's gravatar image

2★sharma_akki
211
accept rate: 0%

thanks man!

(18 Mar '17, 22:49) vivek962★
toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×15,852
×1,688
×862
×81
×45
×32

question asked: 15 Mar '17, 19:03

question was seen: 388 times

last updated: 20 Mar '17, 12:37