Rezultati

Up. imeNalogaJezikRezultatČas oddaje
lml-2018 Arbitraža C++ 100/100OK 13. okt '18 @ 15:31

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 1,484 MiB 0,000 s OK
#2 11/11 6,125 MiB 0,125 s OK
#3 11/11 4,449 MiB 0,070 s OK
#4 11/11 2,992 MiB 0,062 s OK
#5 11/11 4,453 MiB 0,087 s OK
#6 11/11 5,938 MiB 0,087 s OK
#7 11/11 6,000 MiB 0,087 s OK
#8 11/11 1,613 MiB 0,000 s OK
#9 12/12 1,609 MiB 0,000 s OK

Ocenjevani program (Arbitraza2.cpp):
#include <stdio.h>
#include <algorithm>

using namespace std;

int compare(const void* p1,const void* p2)
{
    return 0 - (*((int*)(p1)) - *((int*)(p2)));
}

int main()
{
    long long n, m, k;
    scanf("%lld %lld %lld",&n,&m,&k);
    long long p[100001];
    long long s[100001];

    for(long long i = 0; i < n; i++)
    {
        scanf("%lld",&p[i]);
    }

    for(long long i = 0; i < m; i++)
    {
        scanf("%lld",&s[i]);
    }

    qsort(p,n,sizeof(long long),compare);
    qsort(s,m,sizeof(long long),compare);
    long long l = min(n,k);
    long long o = min(m,k);
    long long a = 0;
    long long b = 0;
    long long c = 0;
    long long sumpr[100001];
    long long sump[100001];
    long long sums[100001];
    sumpr[0] = 0;
    sump[0] = 0;
    sums[0] = 0;

    for(long long i = 1; i <= min(n,m); i++)
    {
        sumpr[i] = sumpr[i - 1] + s[i - 1] * p[i - 1];
    }

    for(long long i = 1; i <= n; i++)
    {
        sump[i] = sump[i - 1] + p[i - 1];
    }

    for(long long i = 1; i <= m; i++)
    {
        sums[i] = sums[i - 1] + s[i - 1];
    }

    if(l + o < k)
    {
        if(l > o)
        {
            long long product = sumpr[o] + sump[l] - sump[o];

            /*for(long long i = 0; i < o; i++)
                product += p[i] * s[i];
            
            for(long long i = o; i < l; i++)
                product += p[i];*/

            c = (l) * product;
        }
        else
        {
            long long product = sumpr[l] + sums[o] - sums[l];

            /*for(long long i = 0; i < l; i++)
                product += p[i] * s[i];
            
            for(long long i = l; i < o; i++)
                product += s[i];*/

            c = (o) * product;
        }

        if(c > b)
            b = c;
    }

    while(l - a >= 0 && k - l + a <= o)
    {
        if(l - a >= k - l + a)
        {
            long long product = sumpr[k - l + a] + sump[l - a] - sump[k - l + a];

            /*for(long long i = 0; i < k - l + a; i++)
                product += p[i] * s[i];
            
            for(long long i = k - l + a; i < l - a; i++)
                product += p[i];*/

            c = (l - a) * product;
        }
        else
        {
            long long product = sumpr[l - a] + sums[k - l + a] - sums[l - a];;

            /*for(long long i = 0; i < l - a; i++)
                product += p[i] * s[i];
            
            for(long long i = l - a; i < k - l + a; i++)
                product += s[i];*/

            c = (k - l + a) * product;
        }

        if(c > b)
            b = c;
        
        a++;
    }

    printf("%lld\n",b);

    /*if(n >= k && m >= k)
    {
        while(l - a >= 0 && k - l + a <= o)
        {
            if(l - a >= k - l + a)
            {
                long long product = 0;

                for(long long i = 0; i < k - l + a; i++)
                    product += p[i] * s[i];
                
                for(long long i = k - l + a; i < l - a; i++)
                    product += p[i];

                c = (l - a) * product;
            }
            else
            {
                long long product = 0;

                for(long long i = 0; i < l - a; i++)
                    product += p[i] * s[i];
                
                for(long long i = l - a; i < k - l + a; i++)
                    product += p[i];

                c = (k - l + a) * product;
            }

            if(c > b)
                b = c;
        }
    }
    else if(n < k && m >= k)
    {
        while(l - a >= 0 && k - l + a <= o)
        {
            if(l - a >= k - l + a)
            {
                long long product = 0;

                for(long long i = 0; i < k - l + a; i++)
                    product += p[i] * s[i];
                
                for(long long i = k - l + a; i < l - a; i++)
                    product += p[i];

                c = (l - a) * product;
            }
            else
            {
                long long product = 0;

                for(long long i = 0; i < l - a; i++)
                    product += p[i] * s[i];
                
                for(long long i = l - a; i < k - l + a; i++)
                    product += p[i];

                c = (k - l + a) * product;
            }

            if(c > b)
                b = c;
        }
    }
    else if(n < k && m >= k)
    {
        while(l - a >= 0 && k - l + a <= o)
        {
            if(l - a >= k - l + a)
            {
                long long product = 0;

                for(long long i = 0; i < k - l + a; i++)
                    product += p[i] * s[i];
                
                for(long long i = k - l + a; i < l - a; i++)
                    product += p[i];

                c = (l - a) * product;
            }
            else
            {
                long long product = 0;

                for(long long i = 0; i < l - a; i++)
                    product += p[i] * s[i];
                
                for(long long i = l - a; i < k - l + a; i++)
                    product += p[i];

                c = (k - l + a) * product;
            }

            if(c > b)
                b = c;
        }
    }
    
    printf("%d\n",b);*/
}