Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MaximalSumOfK
- {
- static void Main()
- {
- int n, k, maxCount = 0, current = 0;
- Console.Write("N= ");
- n = int.Parse(Console.ReadLine());
- Console.Write("K= ");
- k = int.Parse(Console.ReadLine());
- int[] arr = new int[n];
- for(int index = 0; index < n; index++)
- {
- arr [index] = int.Parse(Console.ReadLine());
- }
- for(int indexOne = 0, indexTwo = k-1, indexThree = 0; indexTwo < n; indexOne++, indexTwo++, indexThree++)
- {
- int count = 0;
- for(int index = 0; index < k; index++)
- {
- count += arr[index + indexThree];
- }
- if(count > maxCount)
- {
- maxCount = count;
- current = indexOne;
- }
- else
- {
- continue;
- }
- }
- Console.Write("The biggest sum is " + maxCount + " between ");
- for(int index = 0; index < k; index++)
- {
- Console.Write(arr[current]);
- current++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement