Parallel Processing Solution || Codechef February Lunchtime 2022

      

Parallel Processing Solution 

Codechef February Lunchtime 2022
Problem Code : PLPROCESS

Solution :

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;

void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    if (n == 1)
    {
        cout << a[0] << "\n";
    }
    else
    {
        ll f = a[0], l = a[n - 1];
        ll i = 1, j = n - 2;
        while (i <= j)
        {
            if (f <= l)
            {
                f += a[i];
                i++;
            }
            else
            {
                l += a[j];
                j--;
            }
        }
        cout << max(f, l) << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Comments

Post a Comment