Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using SimpleMvc.Framework.Routers;
- using WebServer.Http;
- namespace SimpleMvc.Framework
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- var nums = Console.ReadLine().Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- var count = 0L;
- var lastMaxIndex = nums.LastIndexOf(nums.Max());
- var currentMax = nums[0];
- for (int i = 0; i < lastMaxIndex; i++)
- {
- if (nums[i] > currentMax)
- {
- currentMax = nums[i];
- }
- count += currentMax;
- }
- currentMax = nums[n - 1];
- for (int i = n - 1; i >= lastMaxIndex; i--)
- {
- if (nums[i] > currentMax)
- {
- currentMax = nums[i];
- }
- count += currentMax;
- }
- Console.WriteLine(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement