Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
1,405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. var elements = Console.ReadLine()
  9. .Split()
  10. .Select(long.Parse)
  11. .ToList();
  12.  
  13. long sum = 0;
  14. while (elements.Count > 0)
  15. {
  16. int index = int.Parse(Console.ReadLine());
  17.  
  18. long element;
  19. if (index < 0)
  20. {
  21. element = elements[0];
  22. elements[0] = elements[elements.Count - 1];
  23. }
  24. else if (index >= elements.Count)
  25. {
  26. element = elements[elements.Count - 1];
  27. elements[elements.Count - 1] = elements[0];
  28. }
  29. else
  30. {
  31. element = elements[index];
  32. elements.RemoveAt(index);
  33. }
  34.  
  35. sum += element;
  36. for (int i = 0; i < elements.Count; i++)
  37. {
  38. if (elements[i] <= element)
  39. {
  40. elements[i] += element;
  41. }
  42. else
  43. {
  44. elements[i] -= element;
  45. }
  46. }
  47. }
  48.  
  49. Console.WriteLine(sum);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement