Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- static void Main(string[] args)
- {
- int[] array = Array.ConvertAll(Console.ReadLine().Split(' '), x => int.Parse(x));
- int len = int.Parse(Console.ReadLine());
- Solve(array, len);
- }
- static void Solve(int[] arr, int len)
- {
- List<int> bestPriceArray = new List<int>();
- int bestPrice = 0;
- for (int i = 1; i <= len; i++)
- {
- int partsToSplitWith = i;
- int lenNumber = len;
- List<int> result = new List<int>();
- int currentPrice = 0;
- while (true)
- {
- if (lenNumber - partsToSplitWith < 0)
- {
- partsToSplitWith -= 1;
- }
- if (lenNumber - partsToSplitWith == 0)
- {
- result.Insert(0, partsToSplitWith);
- currentPrice += arr[partsToSplitWith];
- break;
- }
- if (lenNumber - partsToSplitWith > 0)
- {
- result.Insert(0, partsToSplitWith);
- currentPrice += arr[partsToSplitWith];
- lenNumber -= partsToSplitWith;
- }
- }
- // console.log(result.join(" ") + " currentPrice: " + currentPrice);
- if (bestPrice < currentPrice)
- {
- bestPrice = currentPrice;
- bestPriceArray.Clear();
- for (int t = 0; t < result.Count; t++)
- {
- bestPriceArray.Add(result[t]);
- }
- }
- }
- Console.WriteLine(bestPrice);
- for (int t = 0; t < bestPriceArray.Count; t++)
- {
- if (t >= bestPriceArray.Count - 1)
- {
- Console.Write(bestPriceArray[t]);
- }
- else
- {
- Console.Write(bestPriceArray[t] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement