7318 2024. 01. 07 10:33:55 czita Sípálya (55 pont) csharp Hibás válasz 18/55 486ms 27868 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sipalyak
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] st = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = st[0];
            int K = st[1];
            int[] kszum = new int[K + 1];
            for (int i = 1; i < K + 1; i++)
            {
                kszum[i] =kszum[i-1]+i;
            }
            int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
            //int[] P = { 980855446, 998323020, 997418759, 994832636, 972080651, 973844772, 982446881, 999529807, 994574431, 998939886, 993768883, 999361467, 985621890, 994479633, 992913410, 994225250, 988670181, 992335377, 991835063, 997798360, 993513355, 988058282, 975548123, 999501819, 996917832, 994805932, 984880431, 999542936, 992620889, 996123248 };
            int max = 0, maxi = 0, szum = 0, minepit, max2 = 0, maxi2 = 0;
            for (int i = 0; i < K; i++)
            {
                if (max <= P[i])
                {
                    maxi = i;
                    max = P[i];
                    max2 = max;
                    maxi2 = i;
                }
                else
                {
                    max2--;
                    maxi2++;
                    if (max2 < P[i])
                    {
                        max2 = P[i];
                        maxi2 = i;
                    }
                }
                szum += P[i];
            }
            if (maxi2 - maxi > max - max2)
                minepit = K * max2 - szum + kszum[maxi2  ] - kszum[K - maxi2 - 1];
            else
               minepit = K * max - szum + kszum[maxi ] - kszum[K - maxi - 1];

            int aktepit = 0;
            for (int i = K; i < N; i++)
            {
                szum -= P[i - K];
                szum += P[i];
                if (P[i] >= max)
                {
                    maxi = i;
                    max = P[i];
                    max2 = max;
                    maxi2 = i;
                }
                else
                {
                    max = P[i - K + 1];
                    max2 = P[i-K+1];
                    maxi2 = i - K + 1;
                    maxi = maxi2;
                    for (int j = i-K+1; j < i+1; j++)
                    {
                        if (max <= P[j])
                        {
                            maxi = j;
                            max = P[j];
                            max2 = max;
                            maxi2 = j;
                        }
                        else
                        {
                            max2--;
                            maxi2++;
                            if (max2 < P[j])
                            {
                                max2 = P[j];
                                maxi2 = j;
                            }
                        }
                    }
                    
                }
                if (maxi2 - maxi > max - max2)
                    aktepit = K * max2 - szum + kszum[maxi2 - (i-K+1)] - kszum[i - maxi2];
                else
                    aktepit = K * max - szum + kszum[maxi - (i-K+1) ] - kszum[i - maxi];
                if (minepit > aktepit)
                {
                    minepit = aktepit;
                }
            }
            Console.WriteLine(minepit);
            Console.ReadKey();
        }
    }
}
Részfeladat Összpont Teszt Verdikt Idő Memória
base 18/55
1 Elfogadva 0/0 32ms 22344 KiB
2 Elfogadva 0/0 32ms 22824 KiB
3 Elfogadva 2/2 37ms 23928 KiB
4 Elfogadva 2/2 37ms 23888 KiB
5 Elfogadva 2/2 37ms 24716 KiB
6 Elfogadva 2/2 37ms 24432 KiB
7 Hibás válasz 0/3 37ms 24488 KiB
8 Elfogadva 1/1 64ms 26456 KiB
9 Elfogadva 1/1 71ms 26932 KiB
10 Elfogadva 1/1 75ms 27292 KiB
11 Elfogadva 1/1 86ms 27332 KiB
12 Elfogadva 1/1 83ms 27288 KiB
13 Elfogadva 1/1 143ms 27748 KiB
14 Elfogadva 2/2 157ms 27868 KiB
15 Elfogadva 2/2 86ms 27752 KiB
16 Időlimit túllépés 0/2 467ms 26036 KiB
17 Időlimit túllépés 0/2 462ms 26208 KiB
18 Időlimit túllépés 0/2 458ms 26372 KiB
19 Időlimit túllépés 0/3 486ms 27232 KiB
20 Időlimit túllépés 0/2 462ms 27112 KiB
21 Időlimit túllépés 0/2 477ms 26296 KiB
22 Időlimit túllépés 0/2 469ms 26480 KiB
23 Időlimit túllépés 0/2 469ms 26920 KiB
24 Időlimit túllépés 0/2 477ms 27488 KiB
25 Időlimit túllépés 0/2 453ms 26824 KiB
26 Időlimit túllépés 0/2 469ms 27076 KiB
27 Időlimit túllépés 0/2 465ms 27072 KiB
28 Időlimit túllépés 0/3 477ms 26720 KiB
29 Időlimit túllépés 0/3 465ms 27476 KiB
30 Időlimit túllépés 0/3 481ms 27500 KiB