Given an array/list of length ‘N’, where the array/list represents the boards and each element of the given array/list represents the length of each board. Some ‘K’ numbers of painters are available to paint these boards. Consider that each unit of a board takes 1 unit of time to paint. Skip to main content

Given an array/list of length ‘N’, where the array/list represents the boards and each element of the given array/list represents the length of each board. Some ‘K’ numbers of painters are available to paint these boards. Consider that each unit of a board takes 1 unit of time to paint.

 

Given an array/list of length ‘N’, where the array/list represents the boards and each element of the given array/list represents the length of each board. Some ‘K’ numbers of painters are available to paint these boards. Consider that each unit of a board takes 1 unit of time to paint.

You are supposed to return the area of the minimum time to get this job done of painting all the ‘N’ boards under a constraint that any painter will only paint the continuous sections of boards.

For Example :
In the below figure where array/list elements are {2, 1, 5, 6, 2, 3}.

alt text

A painter can paint blocks {5,6} or {1,5,6,2} together but not {2,5,6} or {5,6,3}.
Input Format :
The first line contains a single integer ‘T’ denoting the number of test cases.

The first line of each test case contains two integers ‘N’ and ‘K’ denoting the number of elements in the array/list and number of painters available.

The second line contains ‘N’ single space-separated integers denoting the elements of the array/list.
Output Format :
For each test case, print the minimum time required to get the job done.
Note :
You do not need to print anything; it has already been taken care of.
Constraints :
1 <= T <= 5
1 <= N <= 10^4
1 <= K <= N
1 <= ARR[i] <= 10^5

Where ‘T’ is the number of test cases.
'N' is the length of the given array/list (boards).
‘K’ is the number of painters available.
And, ARR[i] denotes the i-th element in the array/list.

Time Limit: 1 sec.
Sample Input 1 :
2
4 2
5 5 5 5
4 2
10 20 30 40
Sample Output 1 :
10
60
Explanation For Sample Input 1 :
In the first test case, we can divide the boards into 2 equal-sized partitions, so each painter gets 10 units of the board and the total time taken is 10.


In the second test case, we can divide the first 3 boards for one painter and the last board for the second painter.
Sample Input 2 :
2
2 2
48 90
4 2
1 2 3 4
Sample Output 2 :
90
6
Solution in python:
def painter(boards,cap):
    n=len(boards)
    remcap=cap
    painter1=1
    for i in range(n):  
        if boards[i]<=remcap:
            remcap-= boards[i]
        else:
            painter1=painter1+1
            remcap=cap
            remcap-=boards[i]
    return painter1

Comments

Popular posts from this blog

The average price of 20 paint brush is $15 while average prices of 18 of those is $12 . for the remaining 2 brushes the prices of 1 is 40% more than that of other

 ques 1 .The average price of 20 paint brush is $15 while average prices of 18 of those is $12 . for the remaining 2 brushes the prices of 1 is 40% more than that of other? answer: brush is $35 and other is $49.  ques 2 .the length and breadth of a rectangular field are 45 m and 30m respectively. find the ratio of the breadth to the length of the field? answer: breadth /length=30/45=2/3=2:3.  ques 3 .A certain distance is covered at a certain speed .if half the distance is covered in double the time,the ratio of the two speeds is? answer: 4:1.  ques 4 .Aman sells 5 articles for rs 15 and makes a profit of 20% .find his gain or loss percent if he sells 8 such articles for Rs 18.40? answer: 8%  loss.  ques 5. In what ratio should  a 20 % methyl alcohol solution be mixed with 50% methyl alcohol solution so that the resultant solution  has 40% methyl alcohol in it? answer: 1:2 . 

Unleashing the Future: AI and ML's Impact on You and the World

 Hey there, tech enthusiast! Remember that time you thought self-driving cars were just science fiction? Well, guess what? AI and ML are making it happen, and that's just the tip of the iceberg! These technologies are changing things faster than ever, from healthcare and finance to art and design. It's like having a superpower that helps us create, learn, and solve problems in ways we never imagined. Here's a taste of what's hot right now: * Machines writing amazing stories and translating languages like a pro? It's called "Large Language Models" and it's changing the game for communication and creativity. * Ever heard of AI learning through playing games? It's called "Deep Reinforcement Learning" and it helps robots master complex skills, making them even better at their jobs. * Imagine AI composing music and creating new artwork. That's "Generative AI" at work, and it's opening up a whole new world of possibilities. *

Do you think layoffs from top IT companies are just the beginning and many more will follow?

 ## Layoffs in IT: Just the Beginning or a Temporary Blip? The recent wave of layoffs in top IT companies has sparked concern about the future of the industry and whether this is just the beginning of a wider trend. While it's difficult to predict the future with certainty, several factors suggest both potential risks and opportunities for the tech workforce. **Possible Drivers of Further Layoffs:** * **Economic Slowdown:** Global economic challenges like inflation, rising interest rates, and potential recession could impact demand for IT services and products, leading to workforce adjustments. * **Overhiring:** Rapid expansion during the pandemic might have resulted in overstaffing, necessitating downsizing as the economy slows. * **Technological Advancements:** Automation and AI are rapidly transforming the industry, potentially displacing human workers in certain roles. * **Market Saturation:** Certain segments, like social media and streaming services, might be reaching saturat

Conquering the Cyber Jungle: Your Guide to Digital Safety and Security

Conquering the Cyber Jungle: Your Guide to Digital Safety and Security. Cybersecurity: Keeping Your Digital World Safe (No Worries, It's Not Scary!) Think of the internet as your awesome new neighborhood. It's full of exciting things to explore, like games, shops, and ways to connect with friends. But just like any neighborhood, there are some areas you need to be careful in. That's where cybersecurity comes in! Cybersecurity is like having a friendly neighborhood watch program that keeps your online stuff safe. It's all about protecting your information and devices from bad guys trying to steal it or cause trouble. Here are some simple tips to make your online adventures safe and secure: Choose strong passwords: Imagine a password as your house key. A strong password is like a complicated key that's hard for anyone else to guess. Try mixing uppercase and lowercase letters, numbers, and symbols for extra strength. Be careful what you share online: Think before you

TCS is forcing employees to start work from the office

  TCS is forcing employees to start work from the office , whereas employees don't want to go to the office. 1. How TCS forcing employees to start work from the office : In TCS many projects are there, in one project they have an Hr, a manager, and a team lead.so what they are doing, is they have a daily discussion call, they are adding a manager to the call and then the team lead just initiate the conversation and tends it to work from office status. Suddenly Manager starts giving advice that as covid has ended the world has started working from the office so we should have to start working from the office. I have sent a roster to all team members where I have set three days of work in a week. You must have to come to your depute branch and start work from the office. TCS COMPANY  2. What will happen if the employee didn't go to the office : They have warned that we will cut your leave if all of your leaves will be deducted we will cut your salary and if further, you will not

REET 2022:REET Mains Exam Date release, Notification & Latest Updates| REET level 2 controversy

  REET 2022 pre has been successfully conducted. The REET Mains Exam Date is 4th-5th February 2023. Their is one controversy generated. level 2 students blaiming to government that they have cut down  6000 seats and added in level 1 . Check the information for Notification, Vacancy, and Latest News for Preliminary and Mains exams REET Mains Exam Date is already declared. The exam is scheduled to be held on 4th February 2023 and 5th February 2023. The preliminary exams have been successfully completed and the result is already declared. The candidates who have successfully qualified the exam can apply for the mains exam. Candidates can check the result on the official website. The exam is conducted in level 1 and level 2 prelims exams and result for the same is already released by the Rajasthan Board of Secondary Education (BSER) on the official website. Rajasthan Board of Secondary Education administers the Rajasthan Eligibility Test for teachers. REET ensures fantastic opportunities f

TCS Xplore IRA 6thSep2021 Python and Java SBQ

Create a class Leave with the below attributes:   leaveId of type int leaveType of type String having values as EL/CL/SL noOfDays type int dateOfApplication of type String in the format dd-mm-yy (12-07-21)   Note: leaveType EL represents Earned Leave, CL is Casual Leave and SL is Sick Leave. Assume that Leave details are only for the year 2021.     Create the init method which takes the parameters in the above sequence. The method should set the value of attributes to parameter values.     Create another class Employee with the below two attributes: 1. leaveList of type List having Leave objects 2. leaveBalance of type Dictionary having leaveType as Key and remaining leaves of that type as Value. Eg. {EL:20,CL:2,SL:31}   Create the init method which takes all parameters in the above sequence. The method should set the value of attributes to parameter values inside the method. Create below two methods inside the Employee class:   1. getUpdatedLeaveBalance - This method checks for t

Israel Palestine War - What is Happening - Explained by Dhruv Rathee

 नमस्कार दोस्तों, इजराइल और पलेस्टीन के बीच में एक बार फिर से जंग चिड़ चुकी हैं.7 उक्टूबर, सुभे 6.30 बज़े की बात हैं,जब ज्यादतर इस्रायली लोग अपनी घरों में सो रहे थे,कि आचानक से एर रेड साइरन्स बजने लगते हैं.कुछ ही देर बाद रोकिट्स बरसने लगते हैं इस्रायल के शहरों पर हजारों की संक्या में. इस्रायली डिफेंस फोर्सेज एस्टिमेट करती हैं,2,200 रोकिट्स फायर किये गए.हमास ग्रूब कहता है कि 5,000 रोकिट्स फायर किये गए.अब आमतोर पर इस्रायल के पास एक आइरन डोम सिस्टम हैं. यह दुनिया के वन अवध बेस्ट एर डिफेंस सिस्टम में से हैं.जब भी रोकिट्स की इस तरीके से बरसात होती है,यह लेटिस्ट मिलिटरी टेकनॉलिजी का इस्तिमाल करके उन रोकिट्स को इंटरसेप्ट करता हैऔर हवा में ही डिस्ट्रॉय कर देता है इस्रायल देश को प्रोटेक्टिड रखने के लिए. लेकिन यहाँ पर 5000 रोकिट्स फायर किये गए 20 मिनट के अंदर-अंदर.यह आइरन्डोम सिस्टम भी फेल रहा.हजारों की संख्या में इस्रायल में लोग मारे गएऔर जखमी हुए इन अटैक्स के चलते. यह सरप्राइज अटैक पिछले कई दशकों मेंसबसे बड़ा हमला है जो इस्रायल-पलेस्टीन कॉनफ्लिक्ट में देखा गया हैऔर यह याद दिलाता है योम-किपुर व

Happy Diwali Wishes in English link ,text and Deepawali Greetings 2022

Diwali  is a New Year celebration for Hindus, Jains, Sikhs, and some  Muslims  and  Buddhists . This year, the five-day holiday falls in  October   (starting Monday, October 24, 2022). The festival of lights, popular in South Asian countries and among those of South Asian descent, is marked by oil lamps called diyas, to honor the goddess of wealth and prosperity Lakshmi, and to symbolize the triumph of light over darkness. It's a joyous time, and while it has some religious roots, it's become a secular holiday in many areas of the world and across several cultures. If you or someone you love is celebrating Diwali and you'd like to honor them, these  happy  Diwali wishes  and  Diwali greetings  will surely brighten someone's day. Diwali Wishes 1.  Have a happy  and fresh Diwali  2. May your Diwali be free from darkness and abundant with light 3. Have a fun and festive Diwali 4.  Hoping your Diwali brings health, wealth, and happiness 5.  May your Diwali bring Peace and l