ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1788. On the Benefits of Umbrellas

WA 16
Posted by sianqville 12 May 2012 19:38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1788
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int[] g = new int[n];
            int[] b = new int[m];
            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                g[i] = int.Parse(input[i]);
            }
            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < m; i++)
            {
                b[i] = int.Parse(input[i]);
            }
            int res = int.MaxValue;
            Array.Sort(g);
            Array.Sort(b);
            int ans = 0;
            if (n>=m)
            {
                for (int i = 0; i < n-m; i++)
                {
                    ans += g[i];
                }
                Console.WriteLine(ans);
                return;
            }

            for (int i = 0; i <= n; i++)
            {
                ans = 0;
                for (int j = 0; j < m-i; j++)
                {
                    ans += b[i] * i;
                }
                for (int q = 0; q < n-i; q++)
                {
                    ans += g[q];
                }
                res = Math.Min(res, ans);
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}

Edited by author 15.05.2012 20:33
Re: WA 16
Posted by Erop [USU] 13 May 2012 11:36
2 5
100 100
1 1 1 1 1

ans: 6
Re: WA 16
Posted by sianqville 15 May 2012 20:32
i passed this test corectly, but still have WA16
Re: WA 16
Posted by Erop [USU] 19 May 2012 02:20
2 5
100 100
1 2 3 4 5

ans: 12

just stupid bug, if you will got AC, remove your code from forum ))

Edited by author 19.05.2012 02:24
Re: WA 16
Posted by Lyubomir 10 Jul 2012 18:21
you should change
>ans += b[i] * i;
to
>abs += b[j] * i;
because when i=n you skip the cheapest elements from b[m];

Edited by author 11.07.2012 04:03