Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
Ad icon
🎮 INDIAN PSN GIFT CARDS AVAILABLE NOW! 🎮
madukaperera
Updated:
Tuesday at 12:57 PM
🚀 Google AI PRO – 18 Months | Rs. 850 Only
lkkolla
Updated:
Monday at 4:56 PM
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
[ONLY FOR PROGRAMMERS] Releasing IEEExtreme v10.0 Q1 DOG WALKING
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Sumane123" data-source="post: 20828089" data-attributes="member: 557928"><p style="text-align: center"><span style="font-size: 18px"><span style="color: Red"><strong>Dog Walking</strong></span></span></p> <p style="text-align: center"><span style="font-size: 18px"><span style="color: Red"><strong></strong></span></span></p><p></p><p><span style="font-size: 18px">Your friend, Alice, is starting a dog walking business. She already has K dog walkers employed, and today there are N dogs that need to be walked. Each dog walker can walk multiple dogs at the same time, so the dogs will be arranged into K nonempty groups, and each group will then be walked by a single dog walker. However, smaller dogs can be aggressive towards larger dogs, and that makes it harder to walk them together.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">More formally, if the smallest dog in a group has size a, and the largest dog in the group has size b, then the range of the group is defined as b-a. In particular, the range of a group consisting of a single dog is 0. The smaller the range of a group is, the easier it is to walk that particular group. Hence Alice would like to distribute the dogs among the dog walkers so that the sum of ranges of the groups is minimized. Also, since she doesn't want any of the dog walkers to feel left out, she makes sure each dog walker gets to walk at least one dog.</span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Given N, K and the sizes of the dogs, can you help Alice determine what is the minimum sum of ranges over the K groups if the dogs are arranged optimally?</span></p><p></p><p><span style="font-size: 18px"><span style="color: Red">Input Format</span></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px"><span style="font-size: 18px">The first line of input contains t, 1 ≤ t ≤ 5, which gives the number of test cases.</span></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">Each test case starts with a line containing two integers N, the number of dogs, and K, the number of employees, separated by a single space. Then N lines follow, one for each dog, containing an integer x representing the size of the corresponding dog.</span></p><p></p><p><span style="font-size: 18px"><span style="color: Red">Constraints</span></span></p><p></p><p>1 ≤ K ≤ N ≤ 105, 0 ≤ x ≤ 109</p><p><span style="font-size: 18px"><span style="color: red"><span style="color: Red"></span></span></span></p><p><span style="font-size: 18px"><span style="color: red"><span style="color: Red">Output Format</span></span></span></p><p><span style="font-size: 18px"></span></p><p><span style="font-size: 18px">For each test case, you should output, on a line by itself, the minimum sum of ranges over the K groups if the dogs are arranged optimally.</span></p><p><span style="font-size: 18px"></span></p><p></p><p><span style="color: red"><span style="font-size: 18px"></span></span></p><p><span style="color: red"><span style="font-size: 18px">Sample Input</span></span></p><p></p><p><span style="font-size: 15px">2</span></p><p><span style="font-size: 15px">4 2</span></p><p><span style="font-size: 15px">3</span></p><p><span style="font-size: 15px">5</span></p><p><span style="font-size: 15px">1</span></p><p><span style="font-size: 15px">1</span></p><p><span style="font-size: 15px">5 4</span></p><p><span style="font-size: 15px">30</span></p><p><span style="font-size: 15px">40</span></p><p><span style="font-size: 15px">20</span></p><p><span style="font-size: 15px">41</span></p><p><span style="font-size: 15px">50</span></p><p></p><p><span style="color: red"><span style="font-size: 18px">Sample Output</span></span></p><p></p><p><span style="font-size: 18px">2</span></p><p><span style="font-size: 18px">1</span></p><p><span style="font-size: 18px"></span></p><p><span style="color: red"><span style="font-size: 15px"></span></span></p><p><span style="color: red"><span style="font-size: 15px">Explanation</span></span><span style="font-size: 15px"></span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">In the first test case there are four dogs: one of size 3, one of size 5, and two of size 1. There are two dog walkers, and we want to distribute the dogs among them. One optimal way to do this is to make one dog walker walk the dogs of size 3 and 5, and the other dog walker walk the two dogs of size 1. Then the first group has range 5-3=2, while the second group has range 1-1=0, giving a total of 2+0=2.</span></p><p><span style="font-size: 15px"></span></p><p><span style="font-size: 15px">In the second test case there are dogs of size 30, 40, 20, 41 and 50, and four dog walkers. There are so many dog walkers that we can ask all but one of them to walk a single dog. We will make the last dog walker walk the dogs of size 40 and 41, which gives a range of 41-40=1. All other groups have range 0, so the total is 1.</span></p><p></p><p></p><p><span style="color: DarkOrange"><p style="text-align: center"><span style="font-size: 18px"><span style="font-size: 22px"><strong>solve this if you can <img src="/styles/default/xenforo/smilies/default/yes.gif" class="smilie" loading="lazy" alt=":yes:" title="Yes :yes:" data-shortname=":yes:" /><img src="/styles/default/xenforo/smilies/default/yes.gif" class="smilie" loading="lazy" alt=":yes:" title="Yes :yes:" data-shortname=":yes:" /><img src="/styles/default/xenforo/smilies/default/yes.gif" class="smilie" loading="lazy" alt=":yes:" title="Yes :yes:" data-shortname=":yes:" /></strong></span></span></p></span></p><p style="text-align: center"><span style="color: DarkOrange"><span style="font-size: 18px">solution will be given in 24 hrs</span></p></span></p><p style="text-align: center"><span style="color: DarkOrange"><span style="font-size: 18px"></span></p><p></span></p></blockquote><p></p>
[QUOTE="Sumane123, post: 20828089, member: 557928"] [CENTER][SIZE="5"][COLOR="Red"][B]Dog Walking [/B][/COLOR][/SIZE][/CENTER] [SIZE="5"]Your friend, Alice, is starting a dog walking business. She already has K dog walkers employed, and today there are N dogs that need to be walked. Each dog walker can walk multiple dogs at the same time, so the dogs will be arranged into K nonempty groups, and each group will then be walked by a single dog walker. However, smaller dogs can be aggressive towards larger dogs, and that makes it harder to walk them together. More formally, if the smallest dog in a group has size a, and the largest dog in the group has size b, then the range of the group is defined as b-a. In particular, the range of a group consisting of a single dog is 0. The smaller the range of a group is, the easier it is to walk that particular group. Hence Alice would like to distribute the dogs among the dog walkers so that the sum of ranges of the groups is minimized. Also, since she doesn't want any of the dog walkers to feel left out, she makes sure each dog walker gets to walk at least one dog. Given N, K and the sizes of the dogs, can you help Alice determine what is the minimum sum of ranges over the K groups if the dogs are arranged optimally?[/SIZE] [SIZE="5"][COLOR="Red"]Input Format[/COLOR][/SIZE] [SIZE="5"] [SIZE="5"]The first line of input contains t, 1 ≤ t ≤ 5, which gives the number of test cases.[/SIZE] Each test case starts with a line containing two integers N, the number of dogs, and K, the number of employees, separated by a single space. Then N lines follow, one for each dog, containing an integer x representing the size of the corresponding dog.[/SIZE] [SIZE="5"][COLOR="Red"]Constraints[/COLOR][/SIZE] 1 ≤ K ≤ N ≤ 105, 0 ≤ x ≤ 109 [SIZE="5"][COLOR="red"][COLOR="Red"] Output Format[/COLOR][/COLOR][/SIZE] [SIZE="5"] For each test case, you should output, on a line by itself, the minimum sum of ranges over the K groups if the dogs are arranged optimally. [/SIZE] [COLOR="red"][SIZE="5"] Sample Input[/SIZE][/COLOR] [SIZE="4"]2 4 2 3 5 1 1 5 4 30 40 20 41 50[/SIZE] [COLOR="red"][SIZE="5"]Sample Output[/SIZE][/COLOR] [SIZE="5"]2 1 [/SIZE] [COLOR="red"][SIZE="4"] Explanation[/SIZE][/COLOR][SIZE="4"] In the first test case there are four dogs: one of size 3, one of size 5, and two of size 1. There are two dog walkers, and we want to distribute the dogs among them. One optimal way to do this is to make one dog walker walk the dogs of size 3 and 5, and the other dog walker walk the two dogs of size 1. Then the first group has range 5-3=2, while the second group has range 1-1=0, giving a total of 2+0=2. In the second test case there are dogs of size 30, 40, 20, 41 and 50, and four dog walkers. There are so many dog walkers that we can ask all but one of them to walk a single dog. We will make the last dog walker walk the dogs of size 40 and 41, which gives a range of 41-40=1. All other groups have range 0, so the total is 1.[/SIZE] [COLOR="DarkOrange"][CENTER][SIZE="5"][SIZE="6"][B]solve this if you can :yes::yes::yes:[/B][/SIZE] solution will be given in 24 hrs [/SIZE][/CENTER][/COLOR] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom