Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using SimpleMvc.Framework.Routers;
  4. using WebServer.Http;
  5.  
  6. namespace SimpleMvc.Framework
  7. {
  8. public class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. var n = int.Parse(Console.ReadLine());
  13. var nums = Console.ReadLine().Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  14.  
  15. var count = 0L;
  16. var lastMaxIndex = nums.LastIndexOf(nums.Max());
  17.  
  18. var currentMax = nums[0];
  19. for (int i = 0; i < lastMaxIndex; i++)
  20. {
  21. if (nums[i] > currentMax)
  22. {
  23. currentMax = nums[i];
  24. }
  25. count += currentMax;
  26. }
  27.  
  28. currentMax = nums[n - 1];
  29. for (int i = n - 1; i >= lastMaxIndex; i--)
  30. {
  31. if (nums[i] > currentMax)
  32. {
  33. currentMax = nums[i];
  34. }
  35. count += currentMax;
  36. }
  37.  
  38. Console.WriteLine(count);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement