Submission #45853839


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

public class D
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var (N, M, P) = Scanner.Scan<int, int, long>();
        var A = Scanner.ScanEnumerable<long>().ToArray();
        var B = Scanner.ScanEnumerable<long>().ToArray();
        Array.Sort(A);
        Array.Sort(B);
        var cumB = new long[M + 1];
        for (var i = 0; i < M; i++)
        {
            cumB[i + 1] = cumB[i] + B[i];
        }

        long answer = 0;
        for (var i = 0; i < N; i++)
        {
            var ub = UpperBound(B, Math.Max(0, P - A[i]));
            var x = A[i] * ub + cumB[ub];
            var y = (M - ub) * P;
            answer += x + y;
        }

        Console.WriteLine(answer);
    }

    public static int LowerBound<T>(ReadOnlyMemory<T> source, T key) where T : IComparable<T>
    {
        bool F(int i) => source.Span[i].CompareTo(key) >= 0;
        return BinarySearch(-1, source.Length, F);
    }
    public static int LowerBound<T, U>(ReadOnlyMemory<T> source, Func<T, U> map, U key) where U : IComparable<U>
    {
        bool F(int i) => map(source.Span[i]).CompareTo(key) >= 0;
        return BinarySearch(-1, source.Length, F);
    }
    public static int UpperBound<T>(ReadOnlyMemory<T> source, T key) where T : IComparable<T>
    {
        bool F(int i) => source.Span[i].CompareTo(key) > 0;
        return BinarySearch(-1, source.Length, F);
    }
    public static int UpperBound<T, U>(ReadOnlyMemory<T> source, Func<T, U> map, U key) where U : IComparable<U>
    {
        bool F(int i) => map(source.Span[i]).CompareTo(key) > 0;
        return BinarySearch(-1, source.Length, F);
    }
    public static T BinarySearch<T>(T ng, T ok, Func<T, bool> f) where T : INumber<T> => BinarySearch(ng, ok, f, T.One);
    public static T BinarySearch<T>(T ng, T ok, Func<T, bool> f, T eps) where T : INumber<T>
    {
        var one = T.One;
        var two = one + one;
        while (T.Abs(ok - ng) > eps)
        {
            var m = ng + (ok - ng) / two;
            if (f(m)) ok = m;
            else ng = m;
        }
        return ok;
    }

    public class FenwickTree<T>
        where T : struct, IAdditionOperators<T, T, T>, ISubtractionOperators<T, T, T>, IComparisonOperators<T, T, bool>
    {
        public int Length { get; }
        private readonly T[] _data;
        public FenwickTree(int length)
        {
            if (length < 0) throw new ArgumentOutOfRangeException(nameof(length));
            Length = length;
            _data = new T[length];
        }
        public void Add(int index, T value)
        {
            if (index < 0 || Length <= index) throw new ArgumentOutOfRangeException(nameof(index));
            index++;
            while (index <= Length)
            {
                _data[index - 1] += value;
                index += index & -index;
            }
        }
        public T Sum(int length)
        {
            if (length < 0 || Length < length) throw new ArgumentOutOfRangeException(nameof(length));
            T s = default;
            while (length > 0)
            {
                s += _data[length - 1];
                length -= length & -length;
            }
            return s;
        }
        public T Sum(int left, int right)
        {
            if (left < 0 || right < left || Length < right) throw new ArgumentOutOfRangeException();
            return Sum(right) - Sum(left);
        }
        public int LowerBound(T value) => Bound(value, (x, y) => x <= y);
        public int UpperBound(T value) => Bound(value, (x, y) => x < y);
        private int Bound(T value, Func<T, T, bool> compare)
        {
            if (Length == 0 || compare(value, _data[0])) return 0;
            var x = 0;
            var r = 1;
            while (r < Length) r <<= 1;
            for (var k = r; k > 0; k >>= 1)
            {
                if (x + k - 1 >= Length || compare(value, _data[x + k - 1])) continue;
                value -= _data[x + k - 1];
                x += k;
            }
            return x;
        }
    }

    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

Submission Info

Submission Time
Task D - Set Menu
User AconCavy
Language C# 11.0 (.NET 7.0.7)
Score 400
Code Size 6837 Byte
Status AC
Exec Time 652 ms
Memory 83256 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_handmade_00.txt, 02_handmade_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 57 ms 26556 KiB
00_sample_01.txt AC 57 ms 26756 KiB
00_sample_02.txt AC 53 ms 26976 KiB
01_random_00.txt AC 60 ms 26716 KiB
01_random_01.txt AC 267 ms 50100 KiB
01_random_02.txt AC 301 ms 67680 KiB
01_random_03.txt AC 428 ms 69520 KiB
01_random_04.txt AC 628 ms 81776 KiB
01_random_05.txt AC 282 ms 56236 KiB
01_random_06.txt AC 158 ms 41144 KiB
01_random_07.txt AC 236 ms 44424 KiB
01_random_08.txt AC 432 ms 70008 KiB
01_random_09.txt AC 372 ms 67624 KiB
01_random_10.txt AC 652 ms 81792 KiB
01_random_11.txt AC 192 ms 45704 KiB
01_random_12.txt AC 622 ms 81792 KiB
01_random_13.txt AC 637 ms 82044 KiB
01_random_14.txt AC 318 ms 58896 KiB
01_random_15.txt AC 499 ms 82216 KiB
01_random_16.txt AC 499 ms 82092 KiB
01_random_17.txt AC 491 ms 82124 KiB
01_random_18.txt AC 495 ms 81900 KiB
01_random_19.txt AC 492 ms 82164 KiB
01_random_20.txt AC 499 ms 78336 KiB
01_random_21.txt AC 502 ms 79524 KiB
01_random_22.txt AC 497 ms 79288 KiB
01_random_23.txt AC 505 ms 78260 KiB
01_random_24.txt AC 507 ms 79356 KiB
02_handmade_00.txt AC 52 ms 26396 KiB
02_handmade_01.txt AC 477 ms 83256 KiB