Reading Books

There are n books, and Kotivalo and Justina are going to read them all. For each book, you know the time it takes to read it.

They both read each book from beginning to end, and they cannot read a book at the same time. What is the minimum total time required?

Example:

Input:  n = 3, arr = {2, 8, 3}
Output: 16

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long long readingBooks(long long n,
                vector<long long&arr)
{

    long long sum = 0mx = 0;
    for (long long i = 0i < ni++)
    {
        sum += arr[i];
        mx = max(mxarr[i]);
    }
    return max(sum2 * mx);
}

int main()
{
    long long n = 3;

    vector<long longarr = {283};
    cout << readingBooks(narr<< "\n";

    return 0;
}


No comments:

Post a Comment