Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _11.Problem11
- {
- class SumOfCertainNum
- {
- static void Main(string[] args)
- {
- List<int> array = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- int s = int.Parse(Console.ReadLine());
- List<int> sequence = new List<int>();
- int currSum = 0;
- int maxSum = 0;
- for (int i = 0; i < array.Count-1; i++)
- {
- currSum += array[i] + array[i+1];
- if (currSum > s)
- {
- while (currSum > s)
- {
- array.RemoveAt(array[i]);
- currSum = currSum - array[i];
- }
- if (currSum == s)
- {
- sequence.Add(array[i]);
- //sequence += currSum + " ";
- }
- }
- }
- Console.WriteLine(string.Join(" ", sequence));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement