PRATA SPOJ

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 66 :- PRATA SPOJ

"PRATA - Roti Prata" is another classic problem on the Sphere Online Judge (SPOJ) platform. The problem is described as follows:

Rosie is a chef and she loves her job. She decided to open a new restaurant and named it "Rosie's Roti Prata." She wants to minimize the time it takes to cook prata for her customers. There are N chefs available, and each takes some amount of time to cook a single prata. The customers come one by one, and each customer has a certain rank. The time taken to cook a prata for a customer is (rank * time taken by the chef). Rosie wants to know the minimum time required to cook pratas for all her customers.

The task is to find the minimum time T required to cook pratas for all the customers.

To solve this problem, we can use binary search to find the minimum time T. We will set the search space to be the range from 1 (minimum time) to a large enough upper bound (e.g., 10^8). Then, we will check if it is possible to cook all the pratas in time T. If it is possible, we try to minimize this time by moving to the left half of the search space. Otherwise, we move to the right half.

Here's the C++ implementation of the PRATA problem:

cppCopy code

#include <iostream> #include <vector> #include <algorithm> bool isPossible(std::vector<int>& chefs, int pratas, int timeLimit) {    int pratasCooked = 0;    for (int time : chefs) {        int count = 1;        int timeTaken = time;        while (timeTaken <= timeLimit) {            pratasCooked += count;            count++;            timeTaken += time;        }    }    return pratasCooked >= pratas; } int minCookingTime(std::vector<int>& chefs, int pratas) {    int left = 1;    int right = 1e8; // Upper bound (can be adjusted based on constraints)    int result = -1;    while (left <= right) {        int mid = left + (right - left) / 2;        if (isPossible(chefs, pratas, mid)) {            result = mid;            right = mid - 1;        } else {            left = mid + 1;        }    }    return result; } int main() {    int T;    std::cin >> T;    while (T--) {        int pratas;        std::cin >> pratas;        int N;        std::cin >> N;        std::vector<int> chefs(N);        for (int i = 0; i < N; i++) {            std::cin >> chefs[i];        }        int minTime = minCookingTime(chefs, pratas);        std::cout << minTime << std::endl;    }    return 0; }

Example Input:

Copy code

2 10 4 1 2 3 4 8 5 1 1 1 1 1

Example Output:

Copy code

12 5

In this code, the isPossible function checks if it is possible to cook all the pratas in time timeLimit. The minCookingTime function uses binary search to find the minimum time required to cook all the pratas. The time complexity of this algorithm is O(N * log(maxTime)), where N is the number of chefs and maxTime is the upper bound of the search space.

9. Week4 - Assignments

Comments: 2

profile
@mk.info.work
17-Feb-2024, 10:20 PM

SCIAKU Team please upload 1st video of TREE please please please, please

profile
@na3744
23-Feb-2024, 02:52 AM

I bought this course, it worth it!

profile
@mk.info.work
15-Nov-2023, 10:25 PM

Hi i want to buy this course but you dont have master card payment method please let me know how i can buy it

profile
@sciaku1
11-Jan-2024, 03:23 PM

Dear mk.info.work, Now we have all types of payment options. If you need to purchase just checkout our official website

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?