Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MaxSumOfK
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int k = int.Parse(Console.ReadLine());
- // Read the array
- int[] array = new int[n];
- for (int i = 0; i < n; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- // Compair
- int currentSum = 0;
- int sum = 0;
- for (int i = 0; i < array.Length - k + 1; i++)
- {
- for (int e = 0; e < k; e++)
- {
- currentSum += array[i + e];
- }
- if (currentSum >= sum)
- {
- sum = currentSum;
- currentSum = 0;
- }
- else
- {
- currentSum = 0;
- }
- }
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement