73432024-01-08 08:04:39CsongiSípálya (55 pont)csharpWrong answer 26/55187ms75344 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sipalya
{
    internal class Program
    {
        public static List<long> maxok(List<long> data, int k)
        {
            int n = data.Count;
            List<long> res = new List<long>(n - k + 1);
            Queue<int> dq = new Queue<int>();
            for (int i = 0; i < n; i++)
            {
                while (dq.Count > 0 && i - dq.Peek() >= k) dq.Dequeue();
                while (dq.Count > 0 && data[dq.Peek()] <= data[i]) dq.Dequeue();
                dq.Enqueue(i);
                if (i >= k - 1)
                {
                    res.Add(data[dq.Peek()]);
                }
            }
            return res;
        }

        public static List<long> osszeg(List<long> data, int k)
        {
            int n = data.Count;
            List<long> res = new List<long>(n - k + 1);
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += data[i];
                if (i >= k)
                {
                    sum -= data[i - k];
                }
                if (i >= k - 1)
                {
                    res.Add(sum);
                }
            }
            return res;
        }

        public static void Main()
        {
            int n, k;
            string[] be = Console.ReadLine().Split();
            n = int.Parse(be[0]);
            k = int.Parse(be[1]);
            List<long> magassag = new List<long>(n);
            be = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                magassag.Add(long.Parse(be[i]) + i);
            }
            List<long> maxes = maxok(magassag, k);
            List<long> sums = osszeg(magassag, k);
            long best = long.MaxValue;
            for (int i = 0; i <= n - k; i++)
            {
                long cost = k * maxes[i] - sums[i];
                best = Math.Min(best, cost);
            }
            Console.WriteLine(best);
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base26/55
1Accepted0/028ms21028 KiB
2Wrong answer0/029ms21660 KiB
3Wrong answer0/234ms22628 KiB
4Wrong answer0/235ms22960 KiB
5Wrong answer0/235ms23208 KiB
6Wrong answer0/235ms23532 KiB
7Wrong answer0/335ms23692 KiB
8Accepted1/139ms26012 KiB
9Accepted1/139ms26384 KiB
10Accepted1/139ms26648 KiB
11Accepted1/139ms26900 KiB
12Accepted1/141ms26944 KiB
13Accepted1/141ms27008 KiB
14Wrong answer0/241ms27124 KiB
15Accepted2/241ms26832 KiB
16Wrong answer0/2187ms73384 KiB
17Accepted2/2182ms73780 KiB
18Accepted2/2181ms73664 KiB
19Accepted3/3168ms64432 KiB
20Wrong answer0/2186ms74304 KiB
21Wrong answer0/2185ms73572 KiB
22Wrong answer0/2187ms74040 KiB
23Wrong answer0/2187ms74168 KiB
24Wrong answer0/2184ms75344 KiB
25Wrong answer0/2185ms74504 KiB
26Wrong answer0/2187ms74824 KiB
27Accepted2/2185ms74392 KiB
28Accepted3/3186ms74468 KiB
29Accepted3/3177ms74212 KiB
30Accepted3/3186ms74084 KiB