75002024-01-09 11:25:47PeterSípálya (55 pont)csharpTime limit exceeded 0/55490ms27972 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sipalya
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var sv = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = sv[0]; //hegy hossza
            int K = sv[1]; //sípálya hossza
            var hegy = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int maxertek = 0;
            int maxhely = 0;

            //Maximumkeresés
            for (int i = 0; i < hegy.Length; i++)
            {
                if (hegy[i]>maxertek)
                {
                    maxertek = hegy[i];
                    maxhely = i;
                }
            }

            int[] teljesenatdolozotthegy = new int[N];
            Array.Copy(hegy,teljesenatdolozotthegy,N);
            teljesenatdolozotthegy[maxhely] = maxertek;
            int[] odahordottfoldkupacok = new int[N];

            for (int i = 0; i < maxhely; i++)
            {
                while (teljesenatdolozotthegy[i]<maxertek+maxhely-i)
                {
                    teljesenatdolozotthegy[i]++;
                    odahordottfoldkupacok[i]++;
                }
            }

            int helye = 1;
            for (int i = maxhely+1; i < N; i++)
            {
                while (teljesenatdolozotthegy[i]<maxertek-helye)
                {
                    teljesenatdolozotthegy[i]++;
                    odahordottfoldkupacok[i]++;
                }
                helye++;
            }

            //Legjobb intervallum kiszámítása
            int jelenlegiosszeg = 0;
            int minertek = int.MaxValue;
            int minhely = 0;
            for (int i = 0; i < N-K+1; i++)
            {
                for (int j = i; j < K+i; j++)
                {
                    jelenlegiosszeg += odahordottfoldkupacok[j];
                }

                if (jelenlegiosszeg<minertek)
                {
                    minertek = jelenlegiosszeg;
                    minhely = i;
                }

                jelenlegiosszeg = 0;
            }

            Console.WriteLine(minertek);
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Accepted0/032ms22336 KiB
2Time limit exceeded0/0469ms4400 KiB
3Time limit exceeded0/2469ms4948 KiB
4Time limit exceeded0/2488ms5516 KiB
5Time limit exceeded0/2472ms5492 KiB
6Time limit exceeded0/2456ms5972 KiB
7Time limit exceeded0/3488ms6164 KiB
8Wrong answer0/150ms26412 KiB
9Wrong answer0/148ms26376 KiB
10Wrong answer0/154ms26592 KiB
11Time limit exceeded0/1469ms7356 KiB
12Time limit exceeded0/1423ms26780 KiB
13Time limit exceeded0/1481ms7384 KiB
14Time limit exceeded0/2469ms7472 KiB
15Time limit exceeded0/2437ms7740 KiB
16Time limit exceeded0/2465ms26824 KiB
17Time limit exceeded0/2449ms26708 KiB
18Time limit exceeded0/2465ms27016 KiB
19Time limit exceeded0/3486ms27316 KiB
20Time limit exceeded0/2469ms27396 KiB
21Time limit exceeded0/2474ms27144 KiB
22Time limit exceeded0/2490ms27008 KiB
23Time limit exceeded0/2477ms27244 KiB
24Time limit exceeded0/2474ms27972 KiB
25Time limit exceeded0/2486ms27384 KiB
26Time limit exceeded0/2481ms27392 KiB
27Time limit exceeded0/2477ms27304 KiB
28Time limit exceeded0/3483ms27260 KiB
29Time limit exceeded0/3462ms27652 KiB
30Time limit exceeded0/3446ms27872 KiB